ValueError: данные времени не соответствуют формату «%m/%d/%Y %H:%M:%S.%f» ⇐ Python
-
Anonymous
ValueError: данные времени не соответствуют формату «%m/%d/%Y %H:%M:%S.%f»
Я пишу этот код, чтобы изменить тип столбца «Gmt time». Но я даю «ValueError: данные времени не соответствуют формату». Как я могу преобразовать в типы с плавающей запятой или другие типы, кроме объекта и строки?
Мой код:
path= '/content/drive/MyDrive/H1_ASK_Raw.csv'
dateparse = lambda dates: pd.datetime.strptime(dates, '%m/%d/%Y %H:%M:%S.%f')
df = pd.read_csv(path,sep=',', index_col='Date', parse_dates=['Gmt time'], date_parser=dateparse).fillna(0)
df.head()
Я получаю следующую ошибку:
TypeError Traceback (most recent call last)
/usr/local/lib/python3.7/dist-packages/pandas/io/parsers/base_parser.py in converter(*date_cols)
1038 result = tools.to_datetime(
-> 1039 date_parser(*date_cols), errors="ignore", cache=cache_dates
1040 )
18 frames
TypeError: strptime() argument 1 must be str, not numpy.ndarray
During handling of the above exception, another exception occurred:
ValueError Traceback (most recent call last)
ValueError: time data '05.05.2003 00:00:00.000' does not match format '%m/%d/%Y %H:%M:%S'
During handling of the above exception, another exception occurred:
ValueError Traceback (most recent call last)
/usr/lib/python3.7/_strptime.py in _strptime(data_string, format)
357 if not found:
358 raise ValueError("time data %r does not match format %r" %
--> 359 (data_string, format))
360 if len(data_string) != found.end():
361 raise ValueError("unconverted data remains: %s" %
ValueError: time data '05.05.2003 00:00:00.000' does not match format '%m/%d/%Y %H:%M:%S.%f'
Подробнее здесь: https://stackoverflow.com/questions/719 ... -d-y-hms-f
Я пишу этот код, чтобы изменить тип столбца «Gmt time». Но я даю «ValueError: данные времени не соответствуют формату». Как я могу преобразовать в типы с плавающей запятой или другие типы, кроме объекта и строки?
Мой код:
path= '/content/drive/MyDrive/H1_ASK_Raw.csv'
dateparse = lambda dates: pd.datetime.strptime(dates, '%m/%d/%Y %H:%M:%S.%f')
df = pd.read_csv(path,sep=',', index_col='Date', parse_dates=['Gmt time'], date_parser=dateparse).fillna(0)
df.head()
Я получаю следующую ошибку:
TypeError Traceback (most recent call last)
/usr/local/lib/python3.7/dist-packages/pandas/io/parsers/base_parser.py in converter(*date_cols)
1038 result = tools.to_datetime(
-> 1039 date_parser(*date_cols), errors="ignore", cache=cache_dates
1040 )
18 frames
TypeError: strptime() argument 1 must be str, not numpy.ndarray
During handling of the above exception, another exception occurred:
ValueError Traceback (most recent call last)
ValueError: time data '05.05.2003 00:00:00.000' does not match format '%m/%d/%Y %H:%M:%S'
During handling of the above exception, another exception occurred:
ValueError Traceback (most recent call last)
/usr/lib/python3.7/_strptime.py in _strptime(data_string, format)
357 if not found:
358 raise ValueError("time data %r does not match format %r" %
--> 359 (data_string, format))
360 if len(data_string) != found.end():
361 raise ValueError("unconverted data remains: %s" %
ValueError: time data '05.05.2003 00:00:00.000' does not match format '%m/%d/%Y %H:%M:%S.%f'
Подробнее здесь: https://stackoverflow.com/questions/719 ... -d-y-hms-f
Мобильная версия