Skip to document
Was this document helpful?

10 Minutes to Pandas 1647598775

Course: Computer Programming (CS F111)

334 Documents
Students shared 334 documents in this course
Was this document helpful?
1/2/2016 10 Minutes to pandas — pandas 0.17.1 documentation
http://pandas.pydata.org/pandas-docs/stable/10min.html 1/26
10Minutestopandas
Thisisashortintroductiontopandas,gearedmainlyfornewusers.Youcanseemorecomplex
recipesintheCookbook
Customarily,weimportasfollows:
In [1]: import pandas as pd
In [2]: import numpy as np
In [3]: import matplotlib.pyplot as plt
ObjectCreation
SeetheDataStructureIntrosection
CreatingaSeriesbypassingalistofvalues,lettingpandascreateadefaultintegerindex:
In [4]: s = pd.Series([1,3,5,np.nan,6,8])
In [5]: s
Out[5]:
0 1
1 3
2 5
3 NaN
4 6
5 8
dtype: float64
CreatingaDataFramebypassinganumpyarray,withadatetimeindexandlabeledcolumns:
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-01-04',
'2013-01-05', '2013-01-06'],
dtype='datetime64[ns]', freq='D')
In [8]: df = pd.DataFrame(np.random.randn(6,4), index=dates, columns=list('ABCD'))
In [9]: df
Out[9]:
A B C D
2013-01-01 0.469112 -0.282863 -1.509059 -1.135632
2013-01-02 1.212112 -0.173215 0.119209 -1.044236