I wanted to specify the format of the date because it's in European format(Or else the dates will not be in order after I make it as index column). I did exactly from the tutorial as follow:
But after I execute
df.date=pd.to_datetime(df.date,format='%d.%m.%Y %H:%M:%S.%f')
I get this error
df = pd.read_csv("F:PythonJupyter notesAUDCAD1h.csv")
df.columns = [['date', 'open','high','low','close','volume']]
df.head()
Out[66]:
date open high low close volume
0 01.01.2015 00:00:00.000 GMT-0500 0.94821 0.94821 0.94821 0.94821 0.0
1 01.01.2015 01:00:00.000 GMT-0500 0.94821 0.94821 0.94821 0.94821 0.0
2 01.01.2015 02:00:00.000 GMT-0500 0.94821 0.94821 0.94821 0.94821 0.0
3 01.01.2015 03:00:00.000 GMT-0500 0.94821 0.94821 0.94821 0.94821 0.0
4 01.01.2015 04:00:00.000 GMT-0500 0.94821 0.94821 0.94821 0.94821 0.0
df.Date=pd.to_datetime(df.date,format='%d.%m.%Y %H:%M:%S.%f')
Traceback (most recent call last):
File "<ipython-input-67-29b50fd32986>", line 1, in <module>
df.Date=pd.to_datetime(df.date,format='%d.%m.%Y %H:%M:%S.%f')
File "C:UsersAMAnaconda3libsite-packagespandascoreoolsdatetimes.py", line 376, in to_datetime
result = _assemble_from_unit_mappings(arg, errors=errors)
File "C:UsersAMAnaconda3libsite-packagespandascoreoolsdatetimes.py", line 446, in _assemble_from_unit_mappings
unit = {k: f(k) for k in arg.keys()}
File "C:UsersAMAnaconda3libsite-packagespandascoreoolsdatetimes.py", line 446, in <dictcomp>
unit = {k: f(k) for k in arg.keys()}
File "C:UsersAMAnaconda3libsite-packagespandascoreoolsdatetimes.py", line 441, in f
if value.lower() in _unit_map:
AttributeError: 'tuple' object has no attribute 'lower'
How come I got the error but the one I followed didn't? I copied the code exactly. What's wrong with it? Thanks.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…