KeyError: "None of [['', '']] are in the [columns]" pandas python KeyError: "None of [['', '']] are in the [columns]" pandas python pandas pandas

KeyError: "None of [['', '']] are in the [columns]" pandas python


By the print you posted, it seems like you have whitespaces as delimiters. pd.read_csv will read using , as default separator, so you have to explicitly state it:

pd.read_csv('source.txt',header=0, delim_whitespace=True)


simply write code to create a new CSV file and use a new file

 import numpy as np import pandas as pd import matplotlib.pyplot as plt pd.read_csv('source.txt',header=0, delim_whitespace=True) headers = ['ID','vocab','sumCI','sumnextCI','new_diff'] df.columns = headers  df.to_csv('newsource.txt')


You can try doing this:

pd.read_csv('source.txt',header=0, delim_whitespace=True)

If you have any white spaces in the data you're will get an error, so delim_whitespace is included to remove those in case they're in the data.