将字典列表中的Python时间戳转换为日期
我有一个包含Python时间戳的字典列表。我需要将时间戳转换为常规日期。我本想用一个lamda表达式来做这个,但我无法让它工作。请参见下面的我的代码:将字典列表中的Python时间戳转换为日期,python,timestamp,Python,Timestamp,我有一个包含Python时间戳的字典列表。我需要将时间戳转换为常规日期。我本想用一个lamda表达式来做这个,但我无法让它工作。请参见下面的我的代码: findMatchPlay(newData): i = 0 compList=[] for tPeriod in newData: member = tPeriod['username'] url2 = 'https://api.chess.com/pub/player/{}/matches'.format(member)
findMatchPlay(newData):
i = 0
compList=[]
for tPeriod in newData:
member = tPeriod['username']
url2 = 'https://api.chess.com/pub/player/{}/matches'.format(member)
response = s.get(url2)
response.raise_for_status()
matches = response.json()
for status in matches:
for game in matches[status]:
gString = ''.join(game['club'])
if team in gString:
i = i + 1
compList.append({'player': member,'Date Joined': tPeriod['Date Joined'],
'active': tPeriod['active'],
'status': status, 'games played': i})
compList[0]['Date Joined'] = compList[0]['Date Joined'].apply(lambda x:datetime.fromtimestamp(x))
i = 0
上面的代码给出了以下错误:int'object没有属性'apply'
任何帮助都将不胜感激
compList[0]['Date Joined'] = compList[0]['Date Joined']
应该是
compList[0]['Date Joined'] = datetime.fromtimestamp(compList[0]['Date Joined'])
好的,这是一个巨大的帮助,但我得到了以下错误:TypeError:需要一个整数(得到了类型datetime.datetime)。你能在tPeriod中发布值吗?我试图用像这个datetime这样的“int”来纠正错误。fromtimestamp(int(compList[0]['Date Joined']),但这不起作用。那是不恰当的。我想知道compList[0]['Date Joined']中的值是什么。tPeriod看起来像这样:{'Date Joined':1547992205'active':'weekly','username':'buffalobill57'}{'Date Joined':1547986304'active':'weekly','username':'knightburgler'}