我有一个看起来像这样的 DataFrame
ID Location1 Location2
AAA Here Null
AAA Null There
BBB Here Null
BBB Null There
Run Code Online (Sandbox Code Playgroud)
我想要做的是将每个 ID 的所有内容都拉到一行上以提供以下内容
ID Location1 Location2
AAA Here There
BBB Here There
Run Code Online (Sandbox Code Playgroud)
我在想也许我可能想要使用groupby或transform?
如果有可能会首先非Null每个组值使用DataFrame.replace与GroupBy.first:
df1 = df.replace('Null', np.nan).groupby('ID', as_index=False).first()
print (df1)
ID Location1 Location2
0 AAA Here There
1 BBB Here There
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
32 次 |
| 最近记录: |