python - Replacing missing value with a certain condition
问题描述
I try to fill the missing values in Critic Score by grouping 'Name'.
games['Rating'] = dupliacted_games.groupby('Name')['Rating'].apply(
lambda x: x.fillna(x.value_counts().idxmax()
if x.value_counts().max() >=1
else mode , inplace = False)
)
games['Rating'].fillna(
dupliacted_games['Rating'].value_counts().idxmax(),inplace=True
)
I get this error :
site-packages\pandas\core\generic.py:6287: SettingWithCopyWarning: A value is trying to be set on a copy of a slice from a DataFrame See the caveats in the documentation: http://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy self._update_inplace(new_data)
解决方案
It's not an error. You have two ways:
- Use pd.DataFrame.copy(deep=True)
- Turn off warnings
And always think what you do with your data. Check their size(shape) after groupping, merging e.t.c.
推荐阅读
- functional-programming - 列表 l 中的 mappedList 和 x 是什么?
- r - 使用 gsub 忽略 R 中的正则表达式
- excel - 如何在两个 Excel 工作簿之间复制数据?
- vb.net - 如何在没有循环的情况下直接查找多个文本
- javascript - 根据下面给出的逻辑实现父子关系逻辑
- excel - 复制转置粘贴到下一行的基本代码
- mongodb - 将 AWS EC2 Cloud9 连接到 mongoDB Atlas 集群的最佳方法是什么?
- python - ImportError:没有命名的模块
文件夹内的模块 - r - R中的并行计算:多核“分叉”和雪“分叉”有什么区别?
- java - 使用此模板找不到 div xpath