Tao
Tao

Reputation: 397

Pandas read .csv and set index column

I have a problem when I read a .csv and set the 'Column A' as index column.

df = pd.read_csv(index_col = 'Column A')
print(df.colums)

However, I cannot access 'Column A' anymore. I still want to use it as one column to access its date.

Can anyone help?

Upvotes: 8

Views: 40039

Answers (2)

Gedas Miksenas
Gedas Miksenas

Reputation: 1059

This will do the trick, simple and clean:

df = pd.read_csv().set_index('Column A')

Upvotes: 9

Tao
Tao

Reputation: 397

I found this is very straightforward: just setting index as a column.

df['index1'] = df.index

Upvotes: 5

Related Questions