[英]convert a Python timestamp in a list of dictionaries to a date
我有一個包含 Python 時間戳的字典列表。 我需要將時間戳轉換為常規日期。 我希望使用 lamda 表達式來做到這一點,但我無法讓它工作。 請參閱下面的代碼:
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 has no attribute 'apply'
任何幫助將不勝感激!
compList[0]['Date Joined'] = compList[0]['Date Joined']
應該
compList[0]['Date Joined'] = datetime.fromtimestamp(compList[0]['Date Joined'])
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.