【发布时间】:2021-11-26 01:42:36
【问题描述】:
我有 csv 文件,其中包含缺失的列值,如何从上一行复制缺失的列值?
product_id,name,modifier
1,test,cheese
,test,eggs
,test,onions
2,test2,cheese
,test2,eggs
,test2,onions
高于 CSV 数据,低于输出
import pandas as pd
import numpy as np
df = pd.read_csv("pivot-products.csv")
df.pivot(index='product_id',columns='modifier') # <-- throws error
上面的数据透视代码可以很好地与下面的数据集一起工作,我在其中手动复制了它,如何在 pandas 中清理如下所示?
product_id,name,modifier
1,test,cheese
1,test,eggs
1,test,onions
2,test2,cheese
2,test2,eggs
2,test2,onions
【问题讨论】: