strptime() 参数 1 必须是 str,而不是 Series
strptime() argument 1 must be str, not Series
我想将历史['startTime'] 列中的每一行都转换为日期,但显示错误。
我做错了什么?
import pandas as pd
import requests
from datetime import datetime
historical = requests.get('https://ftx.com/api/markets/usdt-perp/candles?resolution=14400&start_time=1309062800').json()
historical = pd.DataFrame(historical['result'])
historical['startTime'] = datetime.strptime(historical['startTime'], '%d/%m/%y %H')
您得到的是 startTime
字符串,所以让我们先将其转换为日期时间对象。
import pandas as pd
import requests
historical = requests.get(
'https://ftx.com/api/markets/usdt-perp/candles?resolution=14400&start_time=1309062800').json()
historical = pd.DataFrame(historical['result'])
historical['startTime'] = pd.to_datetime(
historical['startTime']).dt.strftime('%d/%m/%y %H')
print(historical)
这是一种完全不需要日期时间库的方法
historical['startTime'] = list([pd.to_datetime(x, format='%d/%m/%y %H') for x in historical['startTime'].to_list()])
我想将历史['startTime'] 列中的每一行都转换为日期,但显示错误。
我做错了什么?
import pandas as pd
import requests
from datetime import datetime
historical = requests.get('https://ftx.com/api/markets/usdt-perp/candles?resolution=14400&start_time=1309062800').json()
historical = pd.DataFrame(historical['result'])
historical['startTime'] = datetime.strptime(historical['startTime'], '%d/%m/%y %H')
您得到的是 startTime
字符串,所以让我们先将其转换为日期时间对象。
import pandas as pd
import requests
historical = requests.get(
'https://ftx.com/api/markets/usdt-perp/candles?resolution=14400&start_time=1309062800').json()
historical = pd.DataFrame(historical['result'])
historical['startTime'] = pd.to_datetime(
historical['startTime']).dt.strftime('%d/%m/%y %H')
print(historical)
这是一种完全不需要日期时间库的方法
historical['startTime'] = list([pd.to_datetime(x, format='%d/%m/%y %H') for x in historical['startTime'].to_list()])