Pandas学习

Pandas 是基于Numpy的一个非常好用的库

Series:

1.Series类似于Python中的list,带有index

import pandas as pd
A=pd.Series([1,3,5,60])
print(A)

输出为:

0 1
1 3
2 5
3 60

dtype: int64

2.采用命令A.index()和A.values来查看index与value的值

RangeIndex(start=0, stop=4, step=1)

[1 3 5 60]

3.isnull()和notnull()判断有没有NAN的元素存在

print(A.isnull())
print(A.notnull())

4.构建Series对象时,index可以为任意的形式(中国历年经历的灾难)

B=pd.Series([1998,2001,2003,2008],index={'洪水','撞机','非典','汶川地震'})
print(B)
洪水      1998
非典      2001
汶川地震    2003
撞机      2008

dtype: int64

DataFrame

DataFrame是一种二维的数据结构,它的竖行称之为columns,横行跟前面的 Series 一样,称之为 index,也就是说可以通过 columns 和 index 来确定一个主句的位置。
data={"name":["google",'yahoo','facebook','Amazon'],"marks":[200,400,800,1000],'price':[9,4,50,10]}
dF=pd.DataFrame(data)
print(dF)
    marks      name      price
0    200     google         9
1    400      yahoo         4
2    800   facebook      50

3   1000    Amazon      10






猜你喜欢

转载自blog.csdn.net/absent1353/article/details/79975746