Pandas 安装

The easiest way to install pandas is to install it as part of the Anaconda distribution, a cross platform distribution for data analysis and scientific computing. This is the recommended installation method for most users.

Instructions for installing from source, PyPI, ActivePython, various Linux distributions, or a development version are also provided.

Plan for dropping Python 2.7

The Python core team plans to stop supporting Python 2.7 on January 1st, 2020. In line with NumPy’s plans, all pandas releases through December 31, 2018 will support Python 2.

The final release before December 31, 2018 will be the last release to support Python 2. The released package will continue to be available on PyPI and through conda.

Starting January 1, 2019, all releases will be Python 3 only.

If there are people interested in continued support for Python 2.7 past December 31, 2018 (either backporting bugfixes or funding) please reach out to the maintainers on the issue tracker.

For more information, see the Python 3 statement and the Porting to Python 3 guide.

Python version support

Officially Python 2.7, 3.5, 3.6, and 3.7.

Installing pandas

Installing with Anaconda

Installing pandas and the rest of the NumPy and SciPy stack can be a little difficult for inexperienced users.

The simplest way to install not only pandas, but Python and the most popular packages that make up the SciPy stack (IPython, NumPy, Matplotlib, …) is with Anaconda, a cross-platform (Linux, Mac OS X, Windows) Python distribution for data analytics and scientific computing.

After running the installer, the user will have access to pandas and the rest of the SciPy stack without needing to install anything else, and without needing to wait for any software to be compiled.

Installation instructions for Anaconda can be found here.

A full list of the packages available as part of the Anaconda distribution can be found here.

Another advantage to installing Anaconda is that you don’t need admin rights to install it. Anaconda can install in the user’s home directory, which makes it trivial to delete Anaconda if you decide (just delete that folder).

Installing with Miniconda

The previous section outlined how to get pandas installed as part of the Anaconda distribution. However this approach means you will install well over one hundred packages and involves downloading the installer which is a few hundred megabytes in size.

If you want to have more control on which packages, or have a limited internet bandwidth, then installing pandas with Miniconda may be a better solution.

Conda is the package manager that the Anaconda distribution is built upon. It is a package manager that is both cross-platform and language agnostic (it can play a similar role to a pip and virtualenv combination).

Miniconda allows you to create a minimal self contained Python installation, and then use the Conda command to install additional packages.

First you will need Conda to be installed and downloading and running the Miniconda will do this for you. The installer can be found here

The next step is to create a new conda environment. A conda environment is like a virtualenv that allows you to specify a specific version of Python and set of libraries. Run the following commands from a terminal window:

  1. conda create -n name_of_my_env python

This will create a minimal environment with only Python installed in it. To put your self inside this environment run:

  1. source activate name_of_my_env

On Windows the command is:

  1. activate name_of_my_env

The final step required is to install pandas. This can be done with the following command:

  1. conda install pandas

To install a specific pandas version:

  1. conda install pandas=0.20.3

To install other packages, IPython for example:

  1. conda install ipython

To install the full Anaconda distribution:

  1. conda install anaconda

If you need packages that are available to pip but not conda, then install pip, and then use pip to install those packages:

  1. conda install pip
  2. pip install django

Installing from PyPI

pandas can be installed via pip from PyPI.

  1. pip install pandas

Installing with ActivePython

Installation instructions for ActivePython can be found here. Versions 2.7 and 3.5 include pandas.

Installing using your Linux distribution’s package manager.

The commands in this table will install pandas for Python 3 from your distribution. To install pandas for Python 2, you may need to use the python-pandas package.

DistributionStatusDownload / Repository LinkInstall method
Debianstableofficial Debian repositorysudo apt-get install
Debian & Ubuntuunstable (latest packages)NeuroDebiansudo apt-get install python3-pandas
Ubuntustableofficial Ubuntu repositorysudo apt-get install python3-pandas
OpenSusestableOpenSuse Repositoryzypper in python3-pandas
Fedorastableofficial Fedora repositorydnf install python3-pandas
Centos/RHELstableEPEL repositoryyum install python3-pandas

However, the packages in the linux package managers are often a few versions behind, so to get the newest version of pandas, it’s recommended to install using the pip or conda methods described above.

Installing from source

See the contributing documentation for complete instructions on building from the git source tree. Further, see creating a development environment if you wish to create a pandas development environment.

Running the test suite

pandas is equipped with an exhaustive set of unit tests, covering about 97% of the codebase as of this writing. To run it on your machine to verify that everything is working (and that you have all of the dependencies, soft and hard, installed), make sure you have pytest and run:

  1. >>> import pandas as pd
  2. >>> pd.test()
  3. running: pytest --skip-slow --skip-network C:\Users\TP\Anaconda3\envs\py36\lib\site-packages\pandas
  4. ============================= test session starts =============================
  5. platform win32 -- Python 3.6.2, pytest-3.2.1, py-1.4.34, pluggy-0.4.0
  6. rootdir: C:\Users\TP\Documents\Python\pandasdev\pandas, inifile: setup.cfg
  7. collected 12145 items / 3 skipped
  8. ..................................................................S......
  9. ........S................................................................
  10. .........................................................................
  11. ==================== 12130 passed, 12 skipped in 368.339 seconds =====================

Dependencies

Recommended Dependencies

  • numexpr: for accelerating certain numerical operations. numexpr uses multiple cores as well as smart chunking and caching to achieve large speedups. If installed, must be Version 2.4.6 or higher.
  • bottleneck: for accelerating certain types of nan evaluations. bottleneck uses specialized cython routines to achieve large speedups. If installed, must be Version 1.0.0 or higher.

Note:You are highly encouraged to install these libraries, as they provide speed improvements, especially when working with large data sets.

Optional Dependencies

  • Cython: Only necessary to build development version. Version 0.24 or higher.

  • SciPy: miscellaneous statistical functions, Version 0.14.0 or higher

  • xarray: pandas like handling for > 2 dims, needed for converting Panels to xarray objects. Version 0.7.0 or higher is recommended.

  • PyTables: necessary for HDF5-based storage. Version 3.0.0 or higher required, Version 3.2.1 or higher highly recommended.

  • Feather Format: necessary for feather-based storage, version 0.3.1 or higher.

  • Apache Parquet, either pyarrow (>= 0.4.1) or fastparquet (>= 0.0.6) for parquet-based storage. The snappy and brotli are available for compression support.

  • SQLAlchemy: for SQL database support. Version 0.8.1 or higher recommended. Besides SQLAlchemy, you also need a database specific driver. You can find an overview of supported drivers for each SQL dialect in the SQLAlchemy docs. Some common drivers are:

    • psycopg2: for PostgreSQL
    • pymysql: for MySQL.
    • SQLite: for SQLite, this is included in Python’s standard library by default.
  • matplotlib: for plotting, Version 1.4.3 or higher.

  • For Excel I/O:

    • xlrd/xlwt: Excel reading (xlrd) and writing (xlwt)
    • openpyxl: openpyxl version 2.4.0 for writing .xlsx files (xlrd >= 0.9.0)
    • XlsxWriter: Alternative Excel writer
  • Jinja2: Template engine for conditional HTML formatting.

  • s3fs: necessary for Amazon S3 access (s3fs >= 0.0.7).

  • blosc: for msgpack compression using blosc

  • One of qtpy (requires PyQt or PySide), PyQt5, PyQt4, pygtk, xsel, or xclip: necessary to use read_clipboard(). Most package managers on Linux distributions will have xclip and/or xsel immediately available for installation.

  • pandas-gbq: for Google BigQuery I/O.

  • Backports.lzma: Only for Python 2, for writing to and/or reading from an xz compressed DataFrame in CSV; Python 3 support is built into the standard library.

  • One of the following combinations of libraries is needed to use the top-level read_html() function: Changed in version 0.23.0.

    Note:If using BeautifulSoup4 a minimum version of 4.2.1 is required

    警告

    Note: if you’re on a system with apt-get you can do

    1. sudo apt-get build-dep python-lxml

    to get the necessary dependencies for installation of lxml. This will prevent further headaches down the line.

Note: Without the optional dependencies, many useful features will not work. Hence, it is highly recommended that you install these. A packaged distribution like Anaconda, ActivePython (version 2.7 or 3.5), or Enthought Canopy may be worth considering.