Skip to content Skip to sidebar Skip to footer

Pandas DataFrame- Finding Index Value For A Column

I have a DataFrame that has columns such as ID, Name, Specification, Time. my file path to open them mc = pd.read_csv('C:\\data.csv', sep = ',', header = 0, dtype = str) When I c

Solution 1:

That's utf-16 BOM, pass encoding='utf-16' to read_csv see: https://en.wikipedia.org/wiki/Byte_order_mark#Representations_of_byte_order_marks_by_encoding

mc = pd.read_csv("C:\\data.csv", sep=",", header=0, dtype=str, encoding='utf-16')

the above should work FE FF is the BOM for utf-16 Big endian to be specific

Also you should use rename rather than try to overwrite the np array value:

mc.rename(columns={mc.columns[0]: "ID"}, inplace=True)

should work correctly


Post a Comment for "Pandas DataFrame- Finding Index Value For A Column"