首页 > 解决方案 > Pandas 在对象列上变换

问题描述

我已经完成了这个线程 - Pandas: Filling missing values by mean in each group to impute the group of mean by using pandas transform function。但是,我所指的列有一个字符串,并且是不同的,例如:汽车型号缺少里程/发动机功率等...查找附加的示例数据,让我知道如何估算值在此处输入图像描述

标签: python-3.xpandastransform

解决方案


编辑:

df = pd.read_csv('../input/vehicle-dataset-from-cardekho/Car details 
v3.csv')

#mileage filled with mean mileage

df['mileage'] = df['mileage'].str.split().str[0].astype(float)
df['mileage'].fillna(df.mileage.mean(), inplace = True)

#engine filled with mean engine

df['engine'].fillna(df.engine.mean(), inplace = True)

#max_power, torque, seats filled with most frequent value

df['max_power'].fillna(df.max_power.value_counts().index[0], inplace = 
True)
df['torque'].fillna(df.torque.value_counts().index[0], inplace = True)
df['seats'].fillna(df.seats.value_counts().index[0], inplace = True)

推荐阅读