知识在于积累,聪明在于学习
Python之Pandas(三)
range数据取值范围为10-13,index索引的范围为3,即0-2
obj_one=pd.Series(range(10,13),index=range(3))
obj_one
obj_two=pd.Series(range(20,25),index=range(5))
obj_two
obj_one+obj_two
obj_one.add(obj_two,fill_value=0)
Series类型由一组数据及与之相关的数据索引组成
range数据取值范围为10-15,index索引为5,3,1,3,2
import pandas as pd
ser_obj=pd.Series(range(10,15),index=[5,3,1,3,2])
ser_obj
ser_obj.sort_index()
ascending=False按索引降序
ser_obj.sort_index(ascending=False)
DataFrame可以设置列名columns与行名index
对DataFrame的索引进行排序
import numpy as np
import pandas as pd
df_obj=pd.DataFrame(np.arange(9).reshape(3,3),index=[4,3,5])
df_obj
相当于df_obj.sort_index(ascending=True)
df_obj.sort_index()
df_obj.sort_index(ascending=False)
np.nan为NaN值
ser_obj=pd.Series([4,np.nan,6,np.nan,-3,2])
ser_obj
ser_obj.sort_values()
df_obj=pd.DataFrame([[0.4,-0.1,-0.3,0.0],[0.2,0.6,-0.1,-0.7],[0.8,0.6,-0.5,0.1]])
df_obj
df_obj.sort_values(by=2)