我有一個pandas DataFrame如下。
df = pd.DataFrame({'id' : [1,1,1,2,2,3,3,3,3,4,4,5,6,6,6,7,7],
'value' : ["first","second","second","first",
"second","first","third","fourth",
python提取指定行和列的數據?"fifth","second","fifth","first",
"first","second","third","fourth","fifth"]})
我想通過[“id”,“value”]分組,并得到每個組的第一行。
id value
0 1 first
python菜鳥教程。1 1 second
2 1 second
3 2 first
4 2 second
5 3 first
DataFrame對某一列進行運算、6 3 third
7 3 fourth
8 3 fifth
9 4 second
10 4 fifth
formdata、11 5 first
12 6 first
13 6 second
14 6 third
15 7 fourth
python二維list取某一列?16 7 fifth
預期結果
id value
1 first
2 first
pandas DataFrame,3 first
4 second
5 first
6 first
7 fourth
python如何按行輸出列表。我試著下面只給出DataFrame的第一行。任何幫助,這是贊賞。
In [25]: for index, row in df.iterrows():
....: df2 = pd.DataFrame(df.groupby(['id','value']).reset_index().ix[0])
版权声明:本站所有资料均为网友推荐收集整理而来,仅供学习和研究交流使用。
工作时间:8:00-18:00
客服电话
电子邮件
admin@qq.com
扫码二维码
获取最新动态