问题在Pandas DataFrame中将列转换为日期格式

时间:2016-11-15 12:05:07

标签: python datetime pandas

将pandas导入pd后,我在pandas数据框中读取了一个csv

In [7]: df = pd.read_csv('data.csv')

In [8]: df
Out[8]: 
              Datetime  MID_S
0     02/04/2015 13:01  75950
1     02/04/2015 13:02  75845
2     02/04/2015 13:03  75770
3     02/04/2015 13:04  75770
4     02/04/2015 13:05  75810
5     02/04/2015 13:06  75875
6     02/04/2015 13:07  75870
7     02/04/2015 13:08  75960
8     02/04/2015 13:09  75970
9     02/04/2015 13:10  75935
10    02/04/2015 13:11  75940
11    02/04/2015 13:12  75855
12    02/04/2015 13:13  75760
13    02/04/2015 13:14  75780
14    02/04/2015 13:15  75720
15    02/04/2015 13:16  75740
16    02/04/2015 13:17  75715
17    02/04/2015 13:18  75760
18    02/04/2015 13:19  75640
19    02/04/2015 13:20  75775
20    02/04/2015 13:21  75775
21    02/04/2015 13:22  75675
22    02/04/2015 13:23  75715
23    02/04/2015 13:24  75770
24    02/04/2015 13:25  75750
25    02/04/2015 13:26  75770
26    02/04/2015 13:27  75740
27    02/04/2015 13:28  75760
28    02/04/2015 13:29  75805
29    02/04/2015 13:30  75790
...                ...    ...
9970  14/04/2015 16:26  75200
9971  14/04/2015 16:27  75195
9972  14/04/2015 16:28  75225
9973  14/04/2015 16:29  75265
9974  14/04/2015 16:30  75265
9975  14/04/2015 16:31  75310
9976  14/04/2015 16:32  75240
9977  14/04/2015 16:33  75220
9978  14/04/2015 16:34  75225
9979  14/04/2015 16:35  75275
9980  14/04/2015 16:36  75300
9981  14/04/2015 16:37  75245
9982  14/04/2015 16:38  75220
9983  14/04/2015 16:39  75245
9984  14/04/2015 16:40  75245
9985  14/04/2015 16:41  75220
9986  14/04/2015 16:42  75230
9987  14/04/2015 16:43  75250
9988  14/04/2015 16:44  75210
9989  14/04/2015 16:45  75220
9990  14/04/2015 16:46  75270
9991  14/04/2015 16:47  75210
9992  14/04/2015 16:48  75215
9993  14/04/2015 16:49  75220
9994  14/04/2015 16:50  75280
9995  14/04/2015 16:51  75270
9996  14/04/2015 16:52  75255
9997  14/04/2015 16:53  75180
9998  14/04/2015 16:54  75220
9999  14/04/2015 16:55  75300

[10000 rows x 2 columns]

当我将MID_S列绘制为plt.plot(df.MID_S)时,我得到了

enter image description here

现在我想将日期时间列转换为日期时间并将其作为索引。我做df.index = pd.to_datetime(df['Datetime'])。但是当我再次绘制plt.plot(df.MID_S)时,我得到了 enter image description here

但我不明白为什么。感谢。

0 个答案:

没有答案