T470_离线安装 pandas

1.

C:\Users\Administrator>pip install pandas
Collecting pandas
  Downloading https://files.pythonhosted.org/packages/b2/56/f886ed6f1777ffa9d54c6e80231b69db8a1f52dcc33f5967b06a105dcfe0/pandas-1.3.5-cp37-cp37m-win_amd64.whl (10.0MB)
     |██▌                             | 808kB 2.8kB/s eta 0:53:37
ERROR: Operation cancelled by user
WARNING: You are using pip version 19.2.3, however version 24.0 is available.
You should consider upgrading via the 'python -m pip install --upgrade pip' command.

C:\Users\Administrator>
C:\Users\Administrator>
C:\Users\Administrator>
C:\Users\Administrator>pip install C:\Users\Administrator\Downloads\pandas-1.3.5-cp37-cp37m-win_amd64.whl
Processing c:\users\administrator\downloads\pandas-1.3.5-cp37-cp37m-win_amd64.whl
Collecting numpy>=1.17.3; platform_machine != "aarch64" and platform_machine != "arm64" and python_version < "3.10" (from pandas==1.3.5)
  Downloading https://files.pythonhosted.org/packages/97/9f/da37cc4a188a1d5d203d65ab28d6504e17594b5342e0c1dc5610ee6f4535/numpy-1.21.6-cp37-cp37m-win_amd64.whl (14.0MB)
     |█▌                              | 716kB 11kB/s eta 0:20:00ERROR: Exception:
Traceback (most recent call last):
  File "c:\users\administrator\appdata\local\programs\python\python37\lib\site-packages\pip\_vendor\urllib3\response.py", line 397, in _error_catcher
    yield
  File "c:\users\administrator\appdata\local\programs\python\python37\lib\site-packages\pip\_vendor\urllib3\response.py", line 479, in read
    data = self._fp.read(amt)
  File "c:\users\administrator\appdata\local\programs\python\python37\lib\site-packages\pip\_vendor\cachecontrol\filewrapper.py", line 62, in read
    data = self.__fp.read(amt)
  File "c:\users\administrator\appdata\local\programs\python\python37\lib\http\client.py", line 457, in read
    n = self.readinto(b)
  File "c:\users\administrator\appdata\local\programs\python\python37\lib\http\client.py", line 501, in readinto
    n = self.fp.readinto(b)
  File "c:\users\administrator\appdata\local\programs\python\python37\lib\socket.py", line 589, in readinto
    return self._sock.recv_into(b)
  File "c:\users\administrator\appdata\local\programs\python\python37\lib\ssl.py", line 1071, in recv_into
    return self.read(nbytes, buffer)
  File "c:\users\administrator\appdata\local\programs\python\python37\lib\ssl.py", line 929, in read
    return self._sslobj.read(len, buffer)
socket.timeout: The read operation timed out

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "c:\users\administrator\appdata\local\programs\python\python37\lib\site-packages\pip\_internal\cli\base_command.py", line 188, in main
    status = self.run(options, args)
  File "c:\users\administrator\appdata\local\programs\python\python37\lib\site-packages\pip\_internal\commands\install.py", line 345, in run
    resolver.resolve(requirement_set)
  File "c:\users\administrator\appdata\local\programs\python\python37\lib\site-packages\pip\_internal\legacy_resolve.py", line 196, in resolve
    self._resolve_one(requirement_set, req)
  File "c:\users\administrator\appdata\local\programs\python\python37\lib\site-packages\pip\_internal\legacy_resolve.py", line 359, in _resolve_one
    abstract_dist = self._get_abstract_dist_for(req_to_install)
  File "c:\users\administrator\appdata\local\programs\python\python37\lib\site-packages\pip\_internal\legacy_resolve.py", line 307, in _get_abstract_dist_for
    self.require_hashes
  File "c:\users\administrator\appdata\local\programs\python\python37\lib\site-packages\pip\_internal\operations\prepare.py", line 199, in prepare_linked_requirement
    progress_bar=self.progress_bar
  File "c:\users\administrator\appdata\local\programs\python\python37\lib\site-packages\pip\_internal\download.py", line 1064, in unpack_url
    progress_bar=progress_bar
  File "c:\users\administrator\appdata\local\programs\python\python37\lib\site-packages\pip\_internal\download.py", line 924, in unpack_http_url
    progress_bar)
  File "c:\users\administrator\appdata\local\programs\python\python37\lib\site-packages\pip\_internal\download.py", line 1152, in _download_http_url
    _download_url(resp, link, content_file, hashes, progress_bar)
  File "c:\users\administrator\appdata\local\programs\python\python37\lib\site-packages\pip\_internal\download.py", line 861, in _download_url
    hashes.check_against_chunks(downloaded_chunks)
  File "c:\users\administrator\appdata\local\programs\python\python37\lib\site-packages\pip\_internal\utils\hashes.py", line 75, in check_against_chunks
    for chunk in chunks:
  File "c:\users\administrator\appdata\local\programs\python\python37\lib\site-packages\pip\_internal\download.py", line 829, in written_chunks
    for chunk in chunks:
  File "c:\users\administrator\appdata\local\programs\python\python37\lib\site-packages\pip\_internal\utils\ui.py", line 156, in iter
    for x in it:
  File "c:\users\administrator\appdata\local\programs\python\python37\lib\site-packages\pip\_internal\download.py", line 818, in resp_read
    decode_content=False):
  File "c:\users\administrator\appdata\local\programs\python\python37\lib\site-packages\pip\_vendor\urllib3\response.py", line 531, in stream
    data = self.read(amt=amt, decode_content=decode_content)
  File "c:\users\administrator\appdata\local\programs\python\python37\lib\site-packages\pip\_vendor\urllib3\response.py", line 496, in read
    raise IncompleteRead(self._fp_bytes_read, self.length_remaining)
  File "c:\users\administrator\appdata\local\programs\python\python37\lib\contextlib.py", line 130, in __exit__
    self.gen.throw(type, value, traceback)
  File "c:\users\administrator\appdata\local\programs\python\python37\lib\site-packages\pip\_vendor\urllib3\response.py", line 402, in _error_catcher
    raise ReadTimeoutError(self._pool, None, 'Read timed out.')
pip._vendor.urllib3.exceptions.ReadTimeoutError: HTTPSConnectionPool(host='files.pythonhosted.org', port=443): Read timed out.
WARNING: You are using pip version 19.2.3, however version 24.0 is available.
You should consider upgrading via the 'python -m pip install --upgrade pip' command.

2.

如果你在离线环境中安装 pandas,记得同时准备好 numpy 的 .whl 文件,并先安装 numpy,再安装 pandas

3.成功安装

C:\Users\Administrator>pip install C:\Users\Administrator\Downloads\numpy-1.21.6-cp37-cp37m-win_amd64.whl
Processing c:\users\administrator\downloads\numpy-1.21.6-cp37-cp37m-win_amd64.whl
Installing collected packages: numpy
Successfully installed numpy-1.21.6
WARNING: You are using pip version 19.2.3, however version 24.0 is available.
You should consider upgrading via the 'python -m pip install --upgrade pip' command.

C:\Users\Administrator>
C:\Users\Administrator>python -c "import numpy; print(numpy.__version__)"

C:\Users\Administrator>pip install C:\Users\Administrator\Downloads\pandas-1.3.5-cp37-cp37m-win_amd64.whl
Processing c:\users\administrator\downloads\pandas-1.3.5-cp37-cp37m-win_amd64.whl
Requirement already satisfied: python-dateutil>=2.7.3 in c:\users\administrator\appdata\local\programs\python\python37\lib\site-packages (from pandas==1.3.5) (2.9.0.post0)
Requirement already satisfied: numpy>=1.17.3; platform_machine != "aarch64" and platform_machine != "arm64" and python_version < "3.10" in c:\users\administrator\appdata\local\programs\python\python37\lib\site-packages (from pandas==1.3.5) (1.21.6)
Collecting pytz>=2017.3 (from pandas==1.3.5)
  Downloading https://files.pythonhosted.org/packages/eb/38/ac33370d784287baa1c3d538978b5e2ea064d4c1b93ffbd12826c190dd10/pytz-2025.1-py2.py3-none-any.whl (507kB)
     |████████████████████████████████| 512kB 211kB/s
Requirement already satisfied: six>=1.5 in c:\users\administrator\appdata\local\programs\python\python37\lib\site-packages (from python-dateutil>=2.7.3->pandas==1.3.5) (1.17.0)
Installing collected packages: pytz, pandas
Successfully installed pandas-1.3.5 pytz-2025.1
WARNING: You are using pip version 19.2.3, however version 24.0 is available.
You should consider upgrading via the 'python -m pip install --upgrade pip' command.

测试

C:\Users\Administrator>pip show pandas
Name: pandas
Version: 1.3.5
Summary: Powerful data structures for data analysis, time series, and statistics
Home-page: https://pandas.pydata.org
Author: The Pandas Development Team
Author-email: pandas-dev@python.org
License: BSD-3-Clause
Location: c:\users\administrator\appdata\local\programs\python\python37\lib\site-packages
Requires: numpy, pytz, python-dateutil
Required-by:

C:\Users\Administrator>
C:\Users\Administrator>
C:\Users\Administrator>pip show numpy
Name: numpy
Version: 1.21.6
Summary: NumPy is the fundamental package for array computing with Python.
Home-page: https://www.numpy.org
Author: Travis E. Oliphant et al.
Author-email: None
License: BSD
Location: c:\users\administrator\appdata\local\programs\python\python37\lib\site-packages
Requires:
Required-by: pandas

有没有工具   分析  whl依赖关系呢

这个网站可以  查询到

PyPI · The Python Package Index

还有命令行查询   

C:\Users\Administrator>pip show  numpy
Name: numpy
Version: 1.21.6
Summary: NumPy is the fundamental package for array computing with Python.
Home-page: https://www.numpy.org
Author: Travis E. Oliphant et al.
Author-email: None
License: BSD
Location: c:\users\administrator\appdata\local\programs\python\python37\lib\site-packages
Requires:
Required-by: pandas

4.安装好了  查看

C:\Users\Administrator\AppData\Local\Programs\Python\Python37\Lib\site-packages

5.还有一种方式  安装 pipdeptree

C:\Users\Administrator>pip install pipdeptree
Collecting pipdeptree
  WARNING: Retrying (Retry(total=4, connect=None, read=None, redirect=None, status=None)) after connection broken by 'ReadTimeoutError("HTTPSConnectionPool(host='pypi.org', port=443): Read timed out. (read timeout=15)")': /simple/pipdeptree/
  Downloading https://files.pythonhosted.org/packages/41/2c/63ad89d8e01d471b91c0ad4d69ed45f5221f70f3ece6c097beecb7c67f7a/pipdeptree-2.9.6-py3-none-any.whl
Installing collected packages: pipdeptree
Successfully installed pipdeptree-2.9.6
WARNING: You are using pip version 19.2.3, however version 24.0 is available.
You should consider upgrading via the 'python -m pip install --upgrade pip' command.

5.1结果显示

C:\Users\Administrator>pipdeptree
hdfs==2.7.3
├── docopt [required: Any, installed: 0.6.2]
├── requests [required: >=2.7.0, installed: 2.31.0]
│   ├── certifi [required: >=2017.4.17, installed: 2025.1.31]
│   ├── charset-normalizer [required: >=2,<4, installed: 3.4.1]
│   ├── idna [required: >=2.5,<4, installed: 3.10]
│   └── urllib3 [required: >=1.21.1,<3, installed: 2.0.7]
└── six [required: >=1.9.0, installed: 1.17.0]
mysql-connector-python==8.0.33
└── protobuf [required: >=3.11.0,<=3.20.3, installed: 3.20.3]
pandas==1.3.5
├── numpy [required: >=1.17.3, installed: 1.21.6]
├── python-dateutil [required: >=2.7.3, installed: 2.9.0.post0]
│   └── six [required: >=1.5, installed: 1.17.0]
└── pytz [required: >=2017.3, installed: 2025.1]
pip==19.2.3
pipdeptree==2.9.6
PyHive==0.7.0
├── future [required: Any, installed: 1.0.0]
└── python-dateutil [required: Any, installed: 2.9.0.post0]
    └── six [required: >=1.5, installed: 1.17.0]
setuptools==41.2.0

C:\Users\Administrator>pipdeptree -p pandas
pandas==1.3.5
├── numpy [required: >=1.17.3, installed: 1.21.6]
├── python-dateutil [required: >=2.7.3, installed: 2.9.0.post0]
│   └── six [required: >=1.5, installed: 1.17.0]
└── pytz [required: >=2017.3, installed: 2025.1]

6.另外一种方法

C:\Users\Administrator>pip install pkginfo
Collecting pkginfo
  Downloading https://files.pythonhosted.org/packages/56/09/054aea9b7534a15ad38a363a2bd974c20646ab1582a387a95b8df1bfea1c/pkginfo-1.10.0-py3-none-any.whl
Installing collected packages: pkginfo
Successfully installed pkginfo-1.10.0
WARNING: You are using pip version 19.2.3, however version 24.0 is available.
You should consider upgrading via the 'python -m pip install --upgrade pip' command.

6.1测试

C:\Users\Administrator>pkginfo  C:\Users\Administrator\Downloads\pandas-1.3.5-cp37-cp37m-win_amd64.whl
metadata_version: 2.1
name: pandas
version: 1.3.5
platforms: ['any']
summary: Powerful data structures for data analysis, time series, and statistics
description: <div align="center">
  <img src="https://pandas.pydata.org/static/img/pandas.svg"><br>
</div>

-----------------

# pandas: powerful Python data analysis toolkit
[![PyPI Latest Release](https://img.shields.io/pypi/v/pandas.svg)](https://pypi.org/project/pandas/)
[![Conda Latest Release](https://anaconda.org/conda-forge/pandas/badges/version.svg)](https://anaconda.org/anaconda/pandas/)
[![DOI](https://zenodo.org/badge/DOI/10.5281/zenodo.3509134.svg)](https://doi.org/10.5281/zenodo.3509134)
[![Package Status](https://img.shields.io/pypi/status/pandas.svg)](https://pypi.org/project/pandas/)
[![License](https://img.shields.io/pypi/l/pandas.svg)](https://github.com/pandas-dev/pandas/blob/master/LICENSE)
[![Azure Build Status](https://dev.azure.com/pandas-dev/pandas/_apis/build/status/pandas-dev.pandas?branch=master)](https://dev.azure.com/pandas-dev/pandas/_build/latest?definitionId=1&branch=master)
[![Coverage](https://codecov.io/github/pandas-dev/pandas/coverage.svg?branch=master)](https://codecov.io/gh/pandas-dev/pandas)
[![Downloads](https://anaconda.org/conda-forge/pandas/badges/downloads.svg)](https://pandas.pydata.org)
[![Gitter](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/pydata/pandas)
[![Powered by NumFOCUS](https://img.shields.io/badge/powered%20by-NumFOCUS-orange.svg?style=flat&colorA=E1523D&colorB=007D8A)](https://numfocus.org)
[![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black)
[![Imports: isort](https://img.shields.io/badge/%20imports-isort-%231674b1?style=flat&labelColor=ef8336)](https://pycqa.github.io/isort/)

## What is it?

**pandas** is a Python package that provides fast, flexible, and expressive data
structures designed to make working with "relational" or "labeled" data both
easy and intuitive. It aims to be the fundamental high-level building block for
doing practical, **real world** data analysis in Python. Additionally, it has
the broader goal of becoming **the most powerful and flexible open source data
analysis / manipulation tool available in any language**. It is already well on
its way towards this goal.

## Main Features
Here are just a few of the things that pandas does well:

  - Easy handling of [**missing data**][missing-data] (represented as
    `NaN`, `NA`, or `NaT`) in floating point as well as non-floating point data
  - Size mutability: columns can be [**inserted and
    deleted**][insertion-deletion] from DataFrame and higher dimensional
    objects
  - Automatic and explicit [**data alignment**][alignment]: objects can
    be explicitly aligned to a set of labels, or the user can simply
    ignore the labels and let `Series`, `DataFrame`, etc. automatically
    align the data for you in computations
  - Powerful, flexible [**group by**][groupby] functionality to perform
    split-apply-combine operations on data sets, for both aggregating
    and transforming data
  - Make it [**easy to convert**][conversion] ragged,
    differently-indexed data in other Python and NumPy data structures
    into DataFrame objects
  - Intelligent label-based [**slicing**][slicing], [**fancy
    indexing**][fancy-indexing], and [**subsetting**][subsetting] of
    large data sets
  - Intuitive [**merging**][merging] and [**joining**][joining] data
    sets
  - Flexible [**reshaping**][reshape] and [**pivoting**][pivot-table] of
    data sets
  - [**Hierarchical**][mi] labeling of axes (possible to have multiple
    labels per tick)
  - Robust IO tools for loading data from [**flat files**][flat-files]
    (CSV and delimited), [**Excel files**][excel], [**databases**][db],
    and saving/loading data from the ultrafast [**HDF5 format**][hdfstore]
  - [**Time series**][timeseries]-specific functionality: date range
    generation and frequency conversion, moving window statistics,
    date shifting and lagging


   [missing-data]: https://pandas.pydata.org/pandas-docs/stable/user_guide/missing_data.html
   [insertion-deletion]: https://pandas.pydata.org/pandas-docs/stable/user_guide/dsintro.html#column-selection-addition-deletion
   [alignment]: https://pandas.pydata.org/pandas-docs/stable/user_guide/dsintro.html?highlight=alignment#intro-to-data-structures
   [groupby]: https://pandas.pydata.org/pandas-docs/stable/user_guide/groupby.html#group-by-split-apply-combine
   [conversion]: https://pandas.pydata.org/pandas-docs/stable/user_guide/dsintro.html#dataframe
   [slicing]: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#slicing-ranges
   [fancy-indexing]: https://pandas.pydata.org/pandas-docs/stable/user_guide/advanced.html#advanced
   [subsetting]: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#boolean-indexing
   [merging]: https://pandas.pydata.org/pandas-docs/stable/user_guide/merging.html#database-style-dataframe-or-named-series-joining-merging
   [joining]: https://pandas.pydata.org/pandas-docs/stable/user_guide/merging.html#joining-on-index
   [reshape]: https://pandas.pydata.org/pandas-docs/stable/user_guide/reshaping.html
   [pivot-table]: https://pandas.pydata.org/pandas-docs/stable/user_guide/reshaping.html
   [mi]: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#hierarchical-indexing-multiindex
   [flat-files]: https://pandas.pydata.org/pandas-docs/stable/user_guide/io.html#csv-text-files
   [excel]: https://pandas.pydata.org/pandas-docs/stable/user_guide/io.html#excel-files
   [db]: https://pandas.pydata.org/pandas-docs/stable/user_guide/io.html#sql-queries
   [hdfstore]: https://pandas.pydata.org/pandas-docs/stable/user_guide/io.html#hdf5-pytables
   [timeseries]: https://pandas.pydata.org/pandas-docs/stable/user_guide/timeseries.html#time-series-date-functionality

## Where to get it
The source code is currently hosted on GitHub at:
https://github.com/pandas-dev/pandas

Binary installers for the latest released version are available at the [Python
Package Index (PyPI)](https://pypi.org/project/pandas) and on [Conda](https://docs.conda.io/en/latest/).

```sh
# conda
conda install pandas
```

```sh
# or PyPI
pip install pandas
```

## Dependencies
- [NumPy - Adds support for large, multi-dimensional arrays, matrices and high-level mathematical functions to operate on these arrays](https://www.numpy.org)
- [python-dateutil - Provides powerful extensions to the standard datetime module](https://dateutil.readthedocs.io/en/stable/index.html)
- [pytz - Brings the Olson tz database into Python which allows accurate and cross platform timezone calculations](https://github.com/stub42/pytz)

See the [full installation instructions](https://pandas.pydata.org/pandas-docs/stable/install.html#dependencies) for minimum supported versions of required, recommended and optional dependencies.

## Installation from sources
To install pandas from source you need [Cython](https://cython.org/) in addition to the normal
dependencies above. Cython can be installed from PyPI:

```sh
pip install cython
```

In the `pandas` directory (same one where you found this file after
cloning the git repo), execute:

```sh
python setup.py install
```

or for installing in [development mode](https://pip.pypa.io/en/latest/cli/pip_install/#install-editable):


```sh
python -m pip install -e . --no-build-isolation --no-use-pep517
```

If you have `make`, you can also use `make develop` to run the same command.

or alternatively

```sh
python setup.py develop
```

See the full instructions for [installing from source](https://pandas.pydata.org/pandas-docs/stable/install.html#installing-from-source).

## License
[BSD 3](LICENSE)

## Documentation
The official documentation is hosted on PyData.org: https://pandas.pydata.org/pandas-docs/stable

## Background
Work on ``pandas`` started at [AQR](https://www.aqr.com/) (a quantitative hedge fund) in 2008 and
has been under active development since then.

## Getting Help

For usage questions, the best place to go to is [StackOverflow](https://stackoverflow.com/questions/tagged/pandas).
Further, general questions and discussions can also take place on the [pydata mailing list](https://groups.google.com/forum/?fromgroups#!forum/pydata).

## Discussion and Development
Most development discussions take place on GitHub in this repo. Further, the [pandas-dev mailing list](https://mail.python.org/mailman/listinfo/pandas-dev) can also be used for specialized discussions or design issues, and a [Gitter channel](https://gitter.im/pydata/pandas) is available for quick development related questions.

## Contributing to pandas [![Open Source Helpers](https://www.codetriage.com/pandas-dev/pandas/badges/users.svg)](https://www.codetriage.com/pandas-dev/pandas)

All contributions, bug reports, bug fixes, documentation improvements, enhancements, and ideas are welcome.

A detailed overview on how to contribute can be found in the **[contributing guide](https://pandas.pydata.org/docs/dev/development/contributing.html)**. There is also an [overview](.github/CONTRIBUTING.md) on GitHub.

If you are simply looking to start working with the pandas codebase, navigate to the [GitHub "issues" tab](https://github.com/pandas-dev/pandas/issues) and start looking through interesting issues. There are a number of issues listed under [Docs](https://github.com/pandas-dev/pandas/issues?labels=Docs&sort=updated&state=open) and [good first issue](https://github.com/pandas-dev/pandas/issues?labels=good+first+issue&sort=updated&state=open) where you could start out.

You can also triage issues which may include reproducing bug reports, or asking for vital information such as version numbers or reproduction instructions. If you would like to start triaging issues, one easy way to get started is to [subscribe to pandas on CodeTriage](https://www.codetriage.com/pandas-dev/pandas).

Or maybe through using pandas you have an idea of your own or are looking for something in the documentation and thinking ‘this can be improved’...you can do something about it!

Feel free to ask questions on the [mailing list](https://groups.google.com/forum/?fromgroups#!forum/pydata) or on [Gitter](https://gitter.im/pydata/pandas).

As contributors and maintainers to this project, you are expected to abide by pandas' code of conduct. More information can be found at: [Contributor Code of Conduct](https://github.com/pandas-dev/pandas/blob/master/.github/CODE_OF_CONDUCT.md)



home_page: https://pandas.pydata.org
author: The Pandas Development Team
author_email: pandas-dev@python.org
license: BSD-3-Clause
classifiers: ['Development Status :: 5 - Production/Stable', 'Environment :: Console', 'Intended Audience :: Science/Research', 'License :: OSI Approved :: BSD License', 'Operating System :: OS Independent', 'Programming Language :: Cython', 'Programming Language :: Python', 'Programming Language :: Python :: 3', 'Programming Language :: Python :: 3 :: Only', 'Programming Language :: Python :: 3.7', 'Programming Language :: Python :: 3.8', 'Programming Language :: Python :: 3.9', 'Programming Language :: Python :: 3.10', 'Topic :: Scientific/Engineering']
requires_python: >=3.7.1
requires_dist: ['python-dateutil (>=2.7.3)', 'pytz (>=2017.3)', 'numpy (>=1.17.3) ; platform_machine != "aarch64" and platform_machine != "arm64" and python_version < "3.10"', 'numpy (>=1.19.2) ; platform_machine == "aarch64" and python_version < "3.10"', 'numpy (>=1.20.0) ; platform_machine == "arm64" and python_version < "3.10"', 'numpy (>=1.21.0) ; python_version >= "3.10"', "hypothesis (>=3.58) ; extra == 'test'", "pytest (>=6.0) ; extra == 'test'", "pytest-xdist ; extra == 'test'"]
project_urls: ['Bug Tracker, https://github.com/pandas-dev/pandas/issues', 'Documentation, https://pandas.pydata.org/pandas-docs/stable', 'Source Code, https://github.com/pandas-dev/pandas']
provides_extras: ['test']
description_content_type: text/markdown

### 插入数据到 Pandas 数据框 在 Pandas 中,可以通过多种方式向 `DataFrame` 添加新数据。以下是几种常见的方法: #### 使用 `.loc[]` 方法插入行 通过指定索引位置并赋值来插入新的行。 ```python import pandas as pd # 创建初始 DataFrame data = {'Name': ['Alice', 'Bob'], 'Age': [25, 30]} df = pd.DataFrame(data) # 插入新行 new_row = {'Name': 'Charlie', 'Age': 35} df.loc[len(df)] = new_row # 将新行追加到最后 print(df) ``` 这种方法适用于逐行添加少量数据[^1]。 #### 使用 `.append()` 方法 `.append()` 是一种简单的方法,用于将另一个 `DataFrame` 或字典附加到现有 `DataFrame` 的底部。 ```python # 新建一个单独的 DataFrame 表示要插入的数据 new_data = pd.DataFrame({'Name': ['David'], 'Age': [40]}) df = df.append(new_data, ignore_index=True) # 设置 ignore_index=True 来重新编号索引 print(df) ``` 需要注意的是,在较新的 Pandas 版本中,推荐使用更高效的方式替代 `.append()`,因为该函数已被标记为过时[^2]。 #### 使用 `.concat()` 合并多个对象 对于批量操作或多维数组的情况,可以利用 `pd.concat()` 函数完成合并任务。 ```python additional_rows = [{'Name': 'Eve', 'Age': 28}, {'Name': 'Frank', 'Age': 32}] temp_df = pd.DataFrame(additional_rows) result = pd.concat([df, temp_df], axis=0).reset_index(drop=True) # reset_index() 可选参数清理旧索引 print(result) ``` 此技术特别适合处理较大的数据集或复杂结构化输入源。 #### 解决常见错误提示 当尝试执行上述任一插入过程时遇到问题,请验证以下几点: - 确认目标列名完全匹配; - 验证待加入记录长度一致于原表宽度; - 如果涉及外部文件加载,则需确认路径正确无误以及依赖库已成功安装(如引用提到 T470 设备上离线部署场景下可能存在的包管理挑战)[^3]。 最后提醒升级至最新版本工具链有助于获得更好的性能表现与功能支持。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值