Fork me on GitHub

python pandas

pandas data structure

Series: one-dimension array, similar to python list, but only can storage same type of data.
Time-Series: index as time series.
DataFrame: two-dimension tablet data structure, similar to R data.frame.
Panel: three-dimension array, container of DataFrame.

install pandas

pip3 install pandas

cookbook of pandas

ipython
import pandas as pd
from pandas import Series

s = Series([1,4,'ww','tt'])
s.index //check the index of series
s.values //check the value of series

s2 = Series(['Wang','man',24], index=['name','sex','age']) //define index of series
s2

sd = {'python':9000, 'c':9001, 'c#':9000}
s3 = Series(sd) //another method to define series
s4 = Series(sd, index=['java','c++','c#'])

pd.isnull(s4) //check the value whether null or not
s4.isnull() //check the object whether null or not

from pandas import Series.DataFrame
data = {"name":['google','baidu','yahoo'], "marks":[100,200,300], "price":[1,2,3]}
f1 = DataFrame(data) // define DataFrame based on dict
f1

f2 = DataFrame(data, columns=['name','price','marks'])
f2

f3 = DataFrame(data, columns=['name','price','marks'], index=['a','b','c'])
f3

newdata = {'lang':{'first':'python','second':'java'}, 'price':{'first':5000,'second':2000}}
f4 = DataFrame(newdata)
f4 //define index for columns and rows

f3['name']

posted @ 2021-01-10 14:06  ~Anti  阅读(52)  评论(0编辑  收藏  举报