I'm trying to rename the first N columns of a DataFrame.
import pandas as pd
Dat = pd.read_csv(inputName, delimiter='\t', header=0)
The original table looks like this:
$Date $ciq_ticker $industry price ...
'09/30/2016 'AAPL' 'Technology' 100.00
'09/30/2016 'AMZN' 'Consumer' 1000.00
...
I want to make some column names more intuitive. What's in my mind is something like this:
descriptors = ['date','ticker','industry']
Dat.columns[:len(descriptors)] = descriptors
This gives an error of "Index does not support mutable operations".
I know something like this works:
Dat.rename(columns={'$Date': 'date', '$ciq_ticker': 'ticker', '$industry': 'industry'}, inplace=True)
But I just don't like the idea of having to type the original column names explicitly. Truth is, the real table has more than 20 columns that I need to modify.