有人遇到过类似我的案件吗? 我正在尝试从pd.read_csv转换datetime值。但是我遇到了错误。
python 3.6.3
熊猫0.25.3
来自CSV的数据:
date, recs, co2v, usg 2018.05.16 9:00, 85.774, 85.777, 85.697 2018.05.16 10:00, 85.712, 85.789, 85.675 2018.05.16 11:00, 85.787, 85.811, 85.657
代码:
20: format = '%Y.%m.%d %H:%S'
21: df['date'] = pd.to_datetime(df['date'], format=format, errors='raise')
22: print(df.info())
23: print(df.head())
错误:
Traceback (most recent call last): File "test1.py", line 21, in df['date'] = pd.to_datetime(df['date'], format=format, errors='raise') File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/pandas/core/frame.py", line 2973, in __getitem__ return self._get_item_cache(key) File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/pandas/core/generic.py", line 3270, in _get_item_cache values = self._data.get(item) File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/pandas/core/internals/managers.py", line 960, in get return self.iget(loc) File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/pandas/core/internals/managers.py", line 977, in iget block = self.blocks[self._blknos[i]] TypeError: only integer scalar arrays can be converted to a scalar index