请原谅标题,我什至不确定如何标记我正在尝试做的事情。我在 DataFrame 中有如下所示的数据:
Name Month Status
---- ----- ------
Bob Jan Good
Bob Feb Good
Bob Mar Bad
Martha Feb Bad
John Jan Good
John Mar Bad
Run Code Online (Sandbox Code Playgroud)
并非每个名称 'Name' 都有每个 'Month' 和 'Status'。我想得到的是:
Name Month Status
---- ----- ------
Bob Jan Good
Bob Feb Good
Bob Mar Bad
Martha Jan N/A
Martha Feb Bad
Martha Mar N/A
John Jan Good
John Feb N/A
John Mar Bad
Run Code Online (Sandbox Code Playgroud)
缺少的月份用“状态”列中的值填充。
到目前为止,我尝试做的是将所有唯一的“Month”值导出到一个列表,转换为 DataFrame,然后加入/合并两个 DataFrame。但我什么也做不了。
做这个的最好方式是什么?