AttributeError:'NoneType'对象没有属性'isnull' [英] AttributeError: 'NoneType' object has no attribute 'isnull'
问题描述
我正在尝试删除空行.但是,当我尝试计算空行以查看是否有效时,出现错误:
I'm trying to remove the empty rows. But when I try to count empty lines to see if it worked, I have an error:
AttributeError:"NoneType"对象没有属性"isnull"
AttributeError: 'NoneType' object has no attribute 'isnull'
我的脚本:
import pandas
import pandas as pd
data = pd.read_csv('data.csv', sep=';')
#print('Table Data\n', data)
data_sum_empty = data.isnull().sum()
#print(data_sum_empty)
data_not_empty = data_sum_empty.dropna(how = 'all', inplace = True)
print(data_not_empty.isnull().sum())
输出:
回溯(最近通话最近一次):
Traceback (most recent call last):
文件.\ data_vis.py",第12行,在 打印(data_not_empty.isnull().sum())
File ".\data_vis.py", line 12, in print(data_not_empty.isnull().sum())
AttributeError:'NoneType'对象没有属性'isnull'
AttributeError: 'NoneType' object has no attribute 'isnull'
某些数据
flightID DepTime ArrTime ActualElapsedTime AirTime ArrDelay
BBYYEUVY67527 1416.0 1514.0 58.0 39.0 64.0
MUPXAQFN40227 2137.0 37.0 120.0 47.0 52.0
LQLYUIMN79169 730.0 916.0 166.0 143.0 -25.0
KTAMHIFO10843 NaN NaN NaN NaN NaN
BOOXJTEY23623 NaN NaN NaN NaN NaN
为什么要重复????我不知道问题出在哪里.如果知道的话,我就不会问了!
推荐答案
使用inplace=True
在df上执行操作时,该操作的变量或输出为None.
When you do an operation on a df with inplace=True
, the variable or output of that operation is None.
data_sum_empty.dropna(how = 'all', inplace = True)
data_not_empty = data_sum_empty.copy()
print(data_not_empty.isnull().sum())
或
data_not_empty = data_sum_empty.dropna(how = 'all')
print(data_not_empty.isnull().sum())
这篇关于AttributeError:'NoneType'对象没有属性'isnull'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!