-1
我有一個名爲construction_year的列作爲數字(int)年份。我想在Python中將它轉換爲dd-mm-yyyy
格式。我已經嘗試過使用datetime和pandas to_datetim並將時間戳轉換爲抽取格式,但徒勞無功。如何在python中將數字年轉換爲日 - 月 - 年格式?
例如:我有像2013年(int)的一年我想將它轉換爲python 3.x中的01-01-2013。
我有一個名爲construction_year的列作爲數字(int)年份。我想在Python中將它轉換爲dd-mm-yyyy
格式。我已經嘗試過使用datetime和pandas to_datetim並將時間戳轉換爲抽取格式,但徒勞無功。如何在python中將數字年轉換爲日 - 月 - 年格式?
例如:我有像2013年(int)的一年我想將它轉換爲python 3.x中的01-01-2013。
如果你想將它轉換成一個字符串,你可以簡單地使用:
convert_string = '01-01-{}'.format
,然後用它喜歡:
>>> convert_string(2013)
'01-01-2013'
如果要將其轉換爲datetime
對象,則可以簡單地使用:
from datetime import date
from functools import partial
convert_to_date = partial(date,month=1,day=1)
現在convert_to_date
是一個數值year
轉換成date
對象的功能:
>>> convert_to_date(2013)
datetime.date(2013, 1, 1)
作爲字符串?或作爲日期時間? –
轉換爲日期格式dd-mm-yyyy – PraveenKumarTelugu