轉換日期的列表中串月,日,年我有日期的列表中,看起來像這樣的字符串:在Python
Date_List
Out[83]:
['2015-08-24 00:00:00',
'2015-08-30 00:00:00',
'2015-08-22 00:00:00',
'2015-08-21 00:00:00',
'2015-08-25 00:00:00',
'2015-08-29 00:00:00']
我希望它是格式如下:
Date_List
Out[83]:
['08-24-2015',
'08-30-2015',
'08-22-2015',
'08-21-2015',
'08-25-2015',
'08-29-2015']
我試圖Date_List = ['{}-{}-{}'.format(m,d,y) for y, m, d in map(lambda x: str(x).split('-'), Date_List)]
這將返回
Date_List
Out[85]:
['08-24 00:00:00-2015',
'08-30 00:00:00-2015',
'08-22 00:00:00-2015',
'08-21 00:00:00-2015',
'08-25 00:00:00-2015',
'08-29 00:00:00-2015']
有人知道如何轉換,並忽略00:00:00
我也試過
但這輸出生成的對象?
Date_List
Out[91]: <generator object <genexpr> at 0x2047A5A8>
這意味着,如果我運行代碼,我得到這個錯誤:TypeError: <generator object <genexpr> at 0x1FBCFC38> is not JSON serializable
啊!哇,我不知道生成器表達式和列表解析之間的區別,很好理解! – jenryb