0

In the following code I get a “KeyError: 0”.

import pandas as pd
import math

data = pd.read_csv(…) #file name and other parameters

data.columns=['UNIX_UTC_Time', 'Home_Team', …] #columns names

matches_number=len(data.index)

def check_data_quality():
    for x in range (matches_number):
        for y in range (11): #number of columns
            if y==1 or y==2: #these columns are strings
                continue     
            if math.isnan(data.at[x,y]):
                print('NaN in:',data.at[x,y],'row',data.iloc[x])

check_data_quality()

Using loc instead of iloc doesn't help either.

If I remove data.columns line, then everything works.

Please let me know how I can print (whole) rows with unintended NaNs here.

Thank you!

DVS75
  • 1
  • 1
  • Does this answer your question? [Selecting pandas column by location](https://stackoverflow.com/questions/14941097/selecting-pandas-column-by-location) – Chris Sep 05 '22 at 18:45

1 Answers1

0

Try replacing data.at[x,y] with data.iloc[x,y].

constantstranger
  • 9,176
  • 2
  • 5
  • 19