我正在为相对人研究数据帧。但是我找不到兄弟,我找不到办法把他们都写在一个特定的专栏上。下面是一个例子:
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
我很感激任何帮助!你知道吗
我认为这应该行得通
下面是一个您可以尝试的想法,首先创建一个
Brother
列,将所有兄弟作为一个包含其自身的列表,然后分别删除其自身。可能会对代码进行优化,但您可以从以下方面入手:相关问题 更多 >
编程相关推荐