![](/img/trans.png)
[英]AttributeError: module 'pandas' has no attribute 'rolling'
[英]Pandas drop null values - AttributeError: module 'pandas' has no attribute 'dropna'
对于当前项目,我试图从数值表中排除所有 null 值。
当应用dropna()
命令“删除”所有不包括数字的值时,我收到以下消息: AttributeError: module 'pandas' has no attribute 'dropna'
。
有什么聪明的调整来让它运行吗? 相应的代码如下所示:
df['Rating_Recommend'] = pd.dropna(df['Rating_Recommend'])
df['Rating_Recommend'] = pd.to_numeric(df['Rating_Recommend'])
rating_recommend = df.Rating_Recommend.mean()
print(rating_recommend)
你能试试这个吗? df['Rating_Recommend'].dropna(inplace=True)
不需要使用pd object来调用dropna() function,直接在data frame上使用即可。
df['Rating_Recommend'] = df['Rating_Recommend'].dropna()
or
df['Rating_Recommend'].dropna(inplace=True)
查看文档以获取更多选项。
https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFrame.dropna.html
dropna()
是一个 DataFrame/Series 方法,而不是模块的 function。所以你需要做这样的事情:
df['Rating_Recommend'].dropna()
但是,这样做毫无意义
df['Rating_Recommend'] = df['Rating_Recommend'].dropna()
相反,从您的代码中,您应该这样做:
df['Rating_Recommend'] = pd.to_numeric(df['Rating_Recommend'], errors='coerce')
rating_mean = df['Rating_Recommend'].mean()
它应该是:
df['Rating_Recommend'] = df['Rating_Recommend'].dropna()
或
df['Rating_Recommend'].dropna(inplace=True)
因为dropna
是pd.DataFrame
和pd.Series
的一种方法。 在您的情况下, df['Rating_Recommend']
是一个 pandas 系列。
有很多选项可以使用 dropna(),我建议你检查一下!!
# Here are all parameters for dropna(). U won't be needing any to just get rid
#of "Nan" and null values, but they do have useful functionalities
DataFrame.dropna(axis=0, how='any', thresh=None, subset=None, inplace=False)
这应该完成你的要求:
df['Rating_Recommend'].dropna(inplace=True)
我希望你检查文档,你会发现它真的很有帮助。 https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFrame.dropna.html
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.