0

I loaded a .csv file successfully. I picked some specific column to fillna with mean that reads like this on spreadsheet "Temperature Difference or Airflow Temperature" but should actually read like this "Temperature Difference or Airflow Temperature". I keep getting errors that call back to that row.

What I have done: Edited the csv columns and taken out the cross sign but that just gives me a Unicode Decode error

For example: output.csv contains the following columns Temperature Difference  and Pressure Difference with some null values.

data.columns = 'Temperature Difference','Pressure Difference'

with no funny character in it.

data['Temperature Difference'].fillna(data['Temperature Difference'].mean(), inplace=True)

gives KeyError: 'Temperature Difference'

Abimbola Ojikutu
  • 447
  • 4
  • 10

1 Answers1

0

You can set the column values with a list. You can do this manually with data.columns = ['Temperature Difference', 'Pressure Difference'].

If you want to do so without knowing the names in advance, you can do either of the following.

data.columns = [''.join([i if ord(i) < 128 else ' ' for i in col]) for col in data.columns]

or

def non_ascii_to_space(s):
    return ''.join([i if ord(i) < 128 else ' ' for i in s])

data.columns = [non_ascii_to_space(col) for col in data.columns]

(based on Replace non-ASCII characters with a single space)

Eric Truett
  • 2,970
  • 1
  • 16
  • 21