我有一个包含 2 列的 Pandas DataFrame。
我用 NaN 替换了 ' ',以便用 fillna 等更快地处理......:
themes = themes.apply(lambda x: x.str.strip()).replace('', np.nan)
如何用其他行的匹配值替换 NaN?
最佳答案
你需要 groupby
和 ffill
和 bfill
themes.groupby('code').apply(lambda x : x.ffill().bfill())
关于python - 替换 Pandas 另一行的缺失值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50195148/