-
data = {
‘name’:[‘张三’,‘李四’,‘王五’,‘小明’],
‘sex’:[‘female’,‘female’,‘male’,‘male’],
‘year’:[2001,2001,2003,2002],
‘city’:[‘北京’,‘上海’,‘广州’,‘北京’] } df=DataFrame(data) df = DataFrame(data,columns=[‘name’,‘city’,‘sex’,‘year’],index =
[‘a’,‘b’,‘c’,‘d’]) -
data2 = {
‘sex’:{‘张三’:‘female’,‘李四’:‘female’,‘王五’:‘male’},
‘city’:{‘张三’:‘北京’,‘李四’:‘上海’,‘王五’:‘广州’} } df2=DataFrame(data2) df2 -
df.index.name = ‘id’
-
df.columns.name =‘std_info’
-
df.values
-
df2.loc[[‘张三’,‘王五’]]
7. ix不用了
df.iloc[[0, 2], [1, 3]]
iloc 需要数字索引 -
df = df.append(new_data,ignore_index=True)
-
new_df.rename(index={3:2,4:3},columns={‘math’:‘Math’},inplace=True)
-
a = {0:4,1:‘sun’,2:100}
df1= df.append(a,ignore_index=True)
python Dataframe
最新推荐文章于 2022-10-09 00:10:33 发布