python-3.x - Pandas 在对象列上变换
问题描述
我已经完成了这个线程 - Pandas: Filling missing values by mean in each group to impute the group of mean by using pandas transform function。但是,我所指的列有一个字符串,并且是不同的,例如:汽车型号缺少里程/发动机功率等...查找附加的示例数据,让我知道如何估算值在此处输入图像描述
解决方案
编辑:
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)
推荐阅读
- c# - 需要字符串格式来显示“否定”值
- android - 在 Android Studio 中使用 Kotlin 更改文本值
- r - 如何在条形图上更正 R 中 y 轴的比例和顺序
- ssl - SSL_connect 返回=1 errno=0 状态=错误:证书验证失败 GitLab Webhook
- python - 如何轻松运行 Sawyer Python 脚本
- powershell - 使用 powershell 和 base64 的自解压存档
- android - Android ValueAnimator 插入疯狂的颜色
- firebase - 如何修复颤振中的警告?
- qt - 在“”中找不到 Qt 平台插件“xcb”
- java - org.apache.cxf.interceptor.Fault:给定的 SOAPAction 与操作不匹配