我正在对相关人员的数据框进行一些调整。但是,当我找到兄弟时,我无法管理,我无法找到一种方法将它们写在特定的专栏上。下面就跟随一个例子:Python Pandas:我如何返回群组的成员
cols = ['Name','Father','Brother']
df = pd.DataFrame({'Brother':'',
'Father':['Erick Moon','Ralph Docker','Erick Moon','Stewart Adborn'],
'Name':['John Smith','Rodolph Ruppert','Mathew Common',"Patrick French"]
},columns=cols)
df
Name Father Brother
0 John Smith Erick Moon
1 Rodolph Ruppert Ralph Docker
2 Mathew Common Erick Moon
3 Patrick French Stewart Adborn
我想是这样的:
Name Father Brother
0 John Smith Erick Moon Mathew Common
1 Rodolph Ruppert Ralph Docker
2 Mathew Common Erick Moon John Smith
3 Patrick French Stewart Adborn
我apreciate任何帮助!
这是否只是数据集包括男性?可以有两个以上的兄弟吗? – ayhan
这个mays是有用的:http://pandas.pydata.org/pandas-docs/stable/reshaping.html –
不,我只是做了一个伪代码。也有女人。另外,这可能不止两个兄弟。我想要重塑。我尝试了groupby,但我无法设法得到其他的兄弟,因为它会重写两次...... – nicmano