I'm trying to change the columns of a dataframe to no avail.
Here is the dataframe:
>>> file = open("data.csv", "r")
>>> data = pd.DataFrame(file)
>>> print(data)
0
0 date,1. open,2. high,3. low,4. close,5. volume\n
1 2020-01-14,316.7,317.57,312.17,312.68,40653457...
2 2020-01-15,311.85,315.5,309.55,311.34,30480882...
3 2020-01-16,313.59,315.7,312.09,315.24,27207254...
Here is the data.rename function to change the column names as documented - https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFrame.rename.html
#Trying to change the columns with a dict
>>> data.rename(columns={"date": "date", "1. open": "open", "2. high": "high", "3. low": "low", "5. volume": "volume"})
0
0 date,1. open,2. high,3. low,4. close,5. volume\n
1 2020-01-14,316.7,317.57,312.17,312.68,40653457...
2 2020-01-15,311.85,315.5,309.55,311.34,30480882...
3 2020-01-16,313.59,315.7,312.09,315.24,27207254...
What am I doing wrong?
Updating: Thanks for all the responses.
I explicitly defined the column that I wanted to see and it all worked perfected.
>>> df.columns = ['col1', 'col2', 'col3', 'col4', 'col5', 'col6']
>>> print (df)
col1 col2 col3 col4 col5 col6
0 2020-01-14 316.70 317.57 312.17 312.68 40653457.0
1 2020-01-15 311.85 315.50 309.55 311.34 30480882.0
2 2020-01-16 313.59 315.70 312.09 315.24 27207254.0
pandas.read_csv. Currently you are producing a single column with the name0.data = pd.read_csv()give you?