直接上代码
Series
import pandas
# print(pandas.Series([232, 455, 2, 3456, 2]))
t = pandas.Series([15,2,3,4,5],index=list("abcde"))
# print(t["c"])
# print(t[1:4])
# print(t[[1,4]])
# print(t[t>2])
print(t.values)
DataFrame
import numpy
import pandas
numpy.random.seed(9)
t = pandas.DataFrame(numpy.random.random(40).reshape(10,4),
index=list("abcdefghij"),columns=list("ABCD"))
# print(t) #同理,t也可以是字典,或者字典构成的列表
# print(t.index)
# print(t.columns)
# print(t.values)
# print(t["D"].mean())
# print(t.shape)
# print(t.dtypes)
# print(t.ndim)
# print(t.info())
# print(t.describe())
# print(t.sort_values(by = "e", ascending= False))
# print(t[:7]) #取前7行
# print(t["B"]) #取列
# print(type(t["B"]))
# print(t.loc["h", :]) #用loc的各种切片。这里注意loc后面是[]
# print(t.loc[["h","a"], ["B","D"]])
# print(t.loc[["h","a"], "A":"C"])
# print(t.iloc[1:8,[3,1]]) #用iloc切片,直接用数字索引
# t = t.iloc[1:4,[3,2,1]] #测试下赋值
# print(t)
# t[t>0.5]=numpy.NaN
# print(t)
# print(t[(t["D"]>0.2)&(t["D"]<0.8)]) #带条件切片,与条件
# print(t[(t["A"]>0.8)|(t["D"]>0.8)]) #带条件切片,或条件
# t = t[t>0.5]
# t2 = pandas.notnull(t) #False为NaN
# # print(t)
# # print(t2)
# # print(t.dropna(how="all")) #删除NaN
# print(t.fillna(8888)) #填充NaN