Pandas KeyError: value not in index

后端 未结 4 957
伪装坚强ぢ
伪装坚强ぢ 2020-12-08 14:06

I have the following code,

df = pd.read_csv(CsvFileName)

p = df.pivot_table(index=[\'Hour\'], columns=\'DOW\', values=\'Changes\', aggfunc=np.mean).round(0         


        
4条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-12-08 15:03

    I had the same issue.

    During the 1st development I used a .csv file (comma as separator) that I've modified a bit before saving it. After saving the commas became semicolon.

    On Windows it is dependent on the "Regional and Language Options" customize screen where you find a List separator. This is the char Windows applications expect to be the CSV separator.

    When testing from a brand new file I encountered that issue.

    I've removed the 'sep' argument in read_csv method before:

    df1 = pd.read_csv('myfile.csv', sep=',');
    

    after:

    df1 = pd.read_csv('myfile.csv');
    

    That way, the issue disappeared.

提交回复
热议问题