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

主宰稳场 提交于 2019-11-30 20:10:17

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)
sejpalsinh jadeja

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')
kaushik Tummalapali

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!