Menu
×
   ❮     
HTML CSS JAVASCRIPT SQL PYTHON JAVA PHP HOW TO W3.CSS C C++ C# BOOTSTRAP REACT MYSQL JQUERY EXCEL XML DJANGO NUMPY PANDAS NODEJS R TYPESCRIPT ANGULAR GIT POSTGRESQL MONGODB ASP AI GO KOTLIN SASS VUE DSA GEN AI SCIPY AWS CYBERSECURITY DATA SCIENCE
     ❯   

Pandas 入门


Pandas 的安装

如果您在系统上已经安装了 PythonPIP,那么安装 Pandas 非常简单。

使用以下命令安装它

C:\Users\您的用户名>pip install pandas

如果此命令失败,请使用已经安装了 Pandas 的 Python 发行版,例如 Anaconda、Spyder 等。


导入 Pandas

Pandas 安装完成后,通过添加 import 关键字将其导入您的应用程序

import pandas

现在 Pandas 已导入并可以使用了。

示例

import pandas

mydataset = {
  'cars': ["BMW", "Volvo", "Ford"],
  'passings': [3, 7, 2]
}

myvar = pandas.DataFrame(mydataset)

print(myvar)
自己尝试 »

w3schools CERTIFIED . 2022

获取认证!

完成 Pandas 模块,完成练习,参加考试,您将获得 w3schools 认证!

10 美元 报名

Pandas 作为 pd

Pandas 通常在 pd 别名下导入。

别名:在 Python 中,别名是引用同一事物的备用名称。

在导入时使用 as 关键字创建别名

import pandas as pd

现在 Pandas 包可以称为 pd 而不是 pandas

示例

import pandas as pd

mydataset = {
  'cars': ["BMW", "Volvo", "Ford"],
  'passings': [3, 7, 2]
}

myvar = pd.DataFrame(mydataset)

print(myvar)
自己尝试 »

检查 Pandas 版本

版本字符串存储在 __version__ 属性下。

示例

import pandas as pd

print(pd.__version__)
自己尝试 »


×

Contact Sales

If you want to use W3Schools services as an educational institution, team or enterprise, send us an e-mail:
[email protected]

Report Error

If you want to report an error, or if you want to make a suggestion, send us an e-mail:
[email protected]

W3Schools is optimized for learning and training. Examples might be simplified to improve reading and learning. Tutorials, references, and examples are constantly reviewed to avoid errors, but we cannot warrant full correctness of all content. While using W3Schools, you agree to have read and accepted our terms of use, cookie and privacy policy.

Copyright 1999-2024 by Refsnes Data. All Rights Reserved. W3Schools is Powered by W3.CSS.