I have .csv file like this:
Str; Int; Flt
A; 123; 0.1
B; 456; 0.2
C; 789; 0.3
I want to get DataFrame like this
Int; Flt
A; 123; 0.1
B; 456; 0.2
C; 789; 0.3
I read csv like this
df = pd.read_csv('data.csv', index_col=0, sep=";")
And the problem is that I can’t use df.loc["A", "Int"] to get cell value.
If I drop Str; from csv everything works fine.
So the idea is to use first row as row names and first column as column names. I understand that first element can’t be used both as col name and row name, is there any way to drop such ambigous value?
>Solution :
Use: index_col='Str' instead of index_col=0
Edited script:
import pandas as pd
df = pd.read_csv("test.csv", sep=";", index_col='Str')
print(df.loc["A", "Int"])
output:
123