parallel_coordinates KeyError when reading CSV with headers

40 Views Asked by At

I am reading in a CSV file with headers - this:

df = pd.read_csv("label-evolution.csv")

print(df)

2021 2022 Name 0 2909 8915 a 1 2027 5088 b 2 12530 29232 c 3 842 2375 a 4 11238 23585 b 5 6961 20533 c 6 1288 4246 d 7 13808 33186 e 8 3360 8847 e 9 7360 16830 f

If I then do: parallel_coordinates(df,'Name')

I get a KeyError on 'Name'.

However, if I do this after reading in the CSV, I get no such error, and all works fine.

df = pd.read_csv("label-evolution.csv")
df.columns=["Nov/Dec 2021","Nov/Dec 2022","Name"]
print(df)

My question is: How do I get the csv file header to work in the expected way, and, as a subsidiary question, what is going on such that the first method produces an error?

I tried the first method, which produced the error.

I found the work-around, which gave the right result, but I would like to read headers straight from the csv

0

There are 0 best solutions below