jupyter_机器学习基础
学习打他frame和一些基础操作
import pandas as pd import numpy as np pd.DataFrame(np.random.randn(2,3)) score=np.random.randint(40,100,(10,5)) score score_df=pd.DataFrame(score) score_df subjects=['语文','数学','英语','体育','政治'] stu=['同学'+str(i) for i in range(score_df.shape[0])] data=pd.DataFrame(score,index=stu,columns=subjects) data data.head(5) data_T=data.T data_T # 重设索引 stu=['同学_'+str(i) for i in range(score_df.shape[0])] data.index=stu data
import pandas as pd datas=pd.read_csv('./data/tianchi_mum_baby.csv') datas datas.iloc[2:4,0:3] datas['birthday'][1]#padans里索引操作先列后行 # 赋值操作 datas['user_id']=1 datas.head(5) ## 排序操作 datas.sort_values(by='birthday',ascending=False).head(5) datas.sort_index().head(5)