Reputation: 934
I'm sure it's something simple that I'm missing but I'm getting this typeError during the 'to_datetime' conversion for the date column which is formatted as 'object.' I have tried different variations of this code but I still get the same error. I'm using the PyCharm IDE.
import pandas as pd
df = pd.read_csv('data/myData.csv')
df.columns = [['date', 'open', 'high', 'low', 'close', 'volume']]
df['date'] = pd.to_datetime(df['date'], format='%m%d%Y:%H:%M:%S.%f')
# print(df.dtypes)
print(df.head())
Upvotes: 4
Views: 1044
Reputation: 863291
Here is problem is convert nested list to columns get one level MultiIndex
.
So for prevent it use:
df.columns = ['date', 'open', 'high', 'low', 'close', 'volume']
Or skip first row in file (original header) and set new header by names
parameter:
df = pd.read_csv('data/myData.csv',
skiprows=1,
names=['date', 'open', 'high', 'low', 'close', 'volume'])
Upvotes: 4