Pandas 简介
Pandas
是一个开源的,BSD许可的库,为Python编程语言提供高性能,易于使用的数据结构和数据分析工具。
Pandas
是NumFOCUS赞助的项目。这将有助于确保Pandas成为世界级开源项目的成功,并有可能捐赠给该项目。
安装
pip install Pandas -i http://mirrors.aliyun.com/pypi/simple/ --trusted-host mirrors.aliyun.com
必要包
import Pandas as pd
import numpy as np
基本用法
数据结构
Series
一维数组,也称序列,与numpy
中的一维array
类似,与基本数据结构list
也很接近。
用于储存一行或一列的数据,以及与之相关的索引的集合。
Series([数据1, 数据2, ...], index = [索引1, 索引2, ...])
>>> import numpy as np
>>> import pandas as pd
>>> x = pd.Series(data = ['a',2,True], index = [1,2,3])
>>> x
1 a
2 2
3 True
dtype: object
# 读取
>>> x[3]
True
# 如果不指定index,默认从0开始
>>> l = np.random.randint(10, 20, size=5)
>>> l
array([14, 14, 13, 12, 12])