0

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' object has no attribute 'isnull'

My script:

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())

Output:

Traceback (most recent call last):

File ".\data_vis.py", line 12, in print(data_not_empty.isnull().sum())

AttributeError: 'NoneType' object has no attribute 'isnull'

Some data

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   

Why duplicate???? I did not know the problem was because of the inplace. If I'd known, I would not have asked!

marin
  • 923
  • 2
  • 18
  • 26

2 Answers2

4

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())

Or

data_not_empty = data_sum_empty.dropna(how = 'all')
print(data_not_empty.isnull().sum())
iDrwish
  • 3,085
  • 1
  • 15
  • 24
3

Do not reassign if you use inplace = True:

data_not_empty = data_sum_empty.dropna(how = 'all')
print(data_not_empty.isnull().sum())
Charles R
  • 1,621
  • 1
  • 8
  • 25