如何将年(2位),月和日的3个单独列合并为单个日期列

时间:2019-02-18 09:49:17

标签: python pandas data-science

我将年,月和日的3个seoerate列合并到数据框的单个列中。但是年份以两位数表示,这有误。

我尝试过to_datetime()在jupyter笔记本中做同样的事情

数据框的格式如下:

Yr Mo Dy   RPT   VAL   ROS   KIL   SHA   BIR   DUB   CLA   MUL   CLO   BEL   
61  1  1 15.04 14.96 13.17  9.29   NaN  9.87 13.67 10.25 10.83 12.58 18.50 
61  1  2 14.71   NaN 10.83  6.50 12.62  7.67 11.50 10.04  9.79  9.67 17.54 
61  1  3 18.50 16.88 12.33 10.13 11.17  6.17 11.25   NaN  8.50  7.67 12.75 


data.rename(columns={'Yr':'Year','Mo':'Month','Dy':'Day'},inplace=True)
data['Date']=pd.to_datetime(data[['Year','Month','Day']],format='%y%m%d')

我得到的错误是:

  

无法组合日期时间:时间数据610101与格式'%Y%m%d'(匹配)不匹配

1 个答案:

答案 0 :(得分:1)

指定列Father的问题public class Father { private String x; protected Father(String x) { this.x = x; System.out.println(this); System.out.println(this.x); } public Father() { this("Father"); } // Rest of father's code, without the init method } public class Son extends Father { public Son() { super("Son"); } // Rest of son's code, without the init method } 需要.green { background: green; color: white; } .white { background: white; color: black; } #sales-list { border: 1px solid black; } td { padding: 10px; border: 1px solid black; } 格式,因此需要替代解决方案,因为年份仅<head> <meta content="text/html; charset=utf-8" http-equiv="Content-Type" /> <title>Untitled 3</title> <link rel="stylesheet" type="text/css" href="Untitled_1.css"/> </head> <body> <script type="text/javascript"> var cells = document.querySelectorAll("td"); for (var i = 0; i < cells.length; i++) { cells[i].addEventListener("click", function() { this.className= this.className == "white" ? "green" : "white"; }); } document.write("Number of green cells: ") </script> <table id="sales-list"> <tr> <td class="white">TEST1</td> <td class="white">TEST2</td> <td class="white">TEST3</td> </tr> </table> </body> </html>

to_datetime