下面是SQL查詢,在新的格式更新日期Python的數據幀列的更新,更換爲每where條件幫助需要
update data set Date=[Time Period]+'-01-01' where Frequency='0'
update data set Date=replace([Time Period],'Q1','-01-01')
where Frequency='2' and substring([Time Period],5,2)='Q1'
update data set Date=replace([Time Period],'Q2','-04-01')
where Frequency='2' and substring([Time Period],5,2)='Q2'
update data set Date=replace([Time Period],'Q3','-07-01')
where Frequency='2' and substring([Time Period],5,2)='Q3'
update data set Date=replace([Time Period],'Q4','-10-01')
where Frequency='2' and substring([Time Period],5,2)='Q4'
update data set Date=replace([Time Period],'M','-')+'-01'
where Frequency='3' and len([Time Period])=7
update data set Date=replace([Time Period],'M','-0')+'-01'
where Frequency='3' and len([Time Period])=6
現在我已經加載相同的數據到Python數據幀,從
的樣本數據數據框用逗號分隔。 列:時間段是輸入數據和日期列是輸出日期,我需要將時間段轉換爲列日期格式。
Frequency,Time Period,Date
0,2008,2008-01-01
0,1961,1961-01-01
2,2009Q1,2009-04-01
2,1975Q4,1975-10-01
2,2007Q3,2007-04-01
2,1959Q4,1959-10-01
2,1965Q4,1965-07-01
2,2008Q3,2008-07-01
3,1969M2,1969-02-01
3,1994M12,1994-12-01
3,1990M1,1990-01-01
3,1994M10,1994-10-01
3,2012M11,2012-11-01
3,1994M3,1994-03-01
請讓我知道如何更新日期根據上述條件在Python中。
能否請您發佈樣本_input_和_output_數據集(5-7行的CSV /字典/ JSON/Python代碼格式__as text__,所以編碼。一個人可以使用它)並描述你想用輸入數據做什麼以獲得輸出數據集? [如何創建一個最小,完整和可驗證的示例](http://stackoverflow.com/help/mcve) – MaxU
最大,我已添加示例數據,請檢查並幫助此... –
現在好多了!請同時發佈__desired__數據集。或者它是「日期」欄 - 它已經是你想要的結果了嗎? – MaxU