从csv中删除NaN值 [英] Removing NaN Values from csv
本文介绍了从csv中删除NaN值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我搜索了有关此主题的几个问题,但没有找到并回答使我的代码正常工作的问题.我是一个初学者,因此非常感谢您的帮助.
I have searched several questions around this topic but have not found and answer that made my code work. I'm a beginner so any help is much appreciated.
我正在使用jupyter笔记本,并且具有以下代码:
I'm using the jupyter notebook and have the following code:
import pandas
a = pandas.read_csv("internal_html.csv")
a.dropna(axis="columns", how="any")
a.head(10)
运行代码时我没有收到任何错误,但仍显示具有NaN值的列.
I get no error when running the code, but the columns with NaN values still show up.
谢谢!
推荐答案
您需要将dropna语句重新分配给a.
You need to reassign the dropna statement back to a.
a = a.dropna(axis="columns", how="any")
默认情况下,dropna
不是就地操作.
或者您可以:
a.dropna(axis="columns", how="any", inplace=True)
编辑以处理源中的空值,如下面的注释所述.
import pandas as pd
import numpy as np
a = pd.read_csv("internal_html.csv")
a = a.replace('',np.nan)
a = a.dropna(axis="columns", how="any")
a.head(10)
这篇关于从csv中删除NaN值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文