My csv file has no column name for the first column, and I want to rename it. Usually, I would do data.rename(columns={'oldname':'newname'}, inplace=True), but there is no name in the csv file, just ''.
40
votes
8 Answers
36
votes
24
votes
When you load the csv, use the option 'index_col' like
pd.read_csv('test.csv', index_col=0)
index_col : int or sequence or False, default None Column to use as the row labels of the DataFrame. If a sequence is given, a MultiIndex is used. If you have a malformed file with delimiters at the end of each line, you might consider index_col=False to force pandas to not use the first column as the index (row names)
http://pandas.pydata.org/pandas-docs/dev/generated/pandas.io.parsers.read_csv.html
10
votes
2
votes
1
votes
pd.read_csv('file.csv', index_col=[0])- EdChum