2024-05-15 02:41:37 发布
网友
起初,DataFrame是这样的:
我想把它改成这样:
你真的需要保留副本吗?如果你没有,那么groupby就是为你做的!你知道吗
groupby
Frame.groupby(['Entity_name','State_Name','State_Group','State_Type']).first()
我想你需要^{}和^{}:
df.set_index(['Entity_Name','State_Name','State_Group','State_Type'], inplace=True) df.sort_index(inplace=True)
样品:
df = pd.DataFrame({'State_Value':[4,5,6], 'State_Type':[7,1,2], 'State_Group':[1,3,5], 'State_Name':[5,3,1], 'Entity_Name':[7,7,7]}) df.set_index(['Entity_Name','State_Name','State_Group','State_Type'], inplace=True) df.sort_index(inplace=True) print (df) State_Value Entity_Name State_Name State_Group State_Type 7 1 5 2 6 3 3 1 5 5 1 7 4
有一个名为itertools的模块。 对特定列使用groupby方法。你知道吗
(如果没有帮助,请告诉我)
你真的需要保留副本吗?如果你没有,那么
groupby
就是为你做的!你知道吗我想你需要^{} 和^{} :
样品:
有一个名为itertools的模块。 对特定列使用groupby方法。你知道吗
(如果没有帮助,请告诉我)
相关问题 更多 >
编程相关推荐