1.1
1.2
1.3
1.3.1
1.3.2
1.3.3
1.3.4
1.3.5
1.3.6
1.3.7
1.3.8
1.3.9
1.4
1.4.1
1.4.2
1.4.3
1.4.4
1.4.5
1.4.6
1.4.7
1.4.8
1.4.9
1.4.10
1.4.11
目錄
Pandas官方教程
十分钟搞定Pandas
Pandas秘籍
第一章
第二章
第三章
第四章
第五章
第六章
第七章
第八章
第九章
学习Pandas
01-Lesson
02-Lesson
03-Lesson
04-Lesson
05-Lesson
06-Lesson
07-Lesson
08-Lesson
09-Lesson
10-Lesson
11-Lesson
1
十分钟搞定pandas
原文:10Minutestopandas
译者:ChaoSimple
来源:【原】十分钟搞定pandas
官方网站上《10Minutestopandas》的一个简单的翻译,原文在这里。这篇文章
是对pandas的一个简单的介绍,详细的介绍请参考:秘籍。习惯上,我们会按下
面格式引入所需要的包:
In[1]:importpandasaspd
In[2]:importnumpyasnp
In[3]:importmatplotlib.pyplotasplt
一、创建对象
可以通过数据结构入门来查看有关该节内容的详细信息。
1、可以通过传递一个 list对象来创建一个 Series,pandas会默认创建整型
索引:
In[4]:s=pd.Series([1,3,5,np.nan,6,8])
In[5]:s
Out[5]:
01.0
13.0
25.0
3NaN
46.0
58.0
dtype:float64
十分钟搞定Pandas
3
2、通过传递一个numpy array,时间索引以及列标签来创建一
个 DataFrame:
In[6]:dates=pd.date_range('20130101',periods=6)
In[7]:dates
Out[7]:
DatetimeIndex(['2013-01-01','2013-01-02','2013-01-03','2013-0
1-04',
'2013-01-05','2013-01-06'],
dtype='datetime64[ns]',freq='D')
In[8]:df=pd.DataFrame(np.random.randn(6,4),index=dates,col
umns=list('ABCD'))
In[9]:df
Out[9]:
ABCD
2013-01-010.469112-0.282863-1.509059-1.135632
2013-01-021.212112-0.1732150.119209-1.044236
2013-01-03-0.861849-2.104569-0.4949291.071804
2013-01-040.721555-0.706771-1.0395750.271860
2013-01-05-0.4249720.5670200.276232-1.087401
2013-01-06-0.6736900.113648-1.4784270.524988
3、通过传递一个能够被转换成类似序列结构的字典对象来创建一
个 DataFrame:
十分钟搞定Pandas
4
In[10]:df2=pd.DataFrame({'A':1.,
....:'B':pd.Timestamp('20130102'),
....:'C':pd.Series(1,index=list(range(
4)),dtype='float32'),
....:'D':np.array([3]*4,dtype='int3
2'),
....:'E':pd.Categorical(["test","trai
n","test","train"]),
....:'F':'foo'})
....:
In[11]:df2
Out[11]:
ABCDEF
01.02013-01-021.03testfoo
11.02013-01-021.03trainfoo
21.02013-01-021.03testfoo
31.02013-01-021.03trainfoo
4、查看不同列的数据类型:
In[12]:df2.dtypes
Out[12]:
Afloat64
Bdatetime64[ns]
Cfloat32
Dint32
Ecategory
Fobject
dtype:object
5、如果你使用的是IPython,使用Tab自动补全功能会自动识别所有的属性以及自
定义的列,下图中是所有能够被自动识别的属性的一个子集:
十分钟搞定Pandas
5