Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/variables/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python熊猫从列表到数据帧的类似于读取csv的功能?_Python_Datetime_Csv_Pandas - Fatal编程技术网

Python熊猫从列表到数据帧的类似于读取csv的功能?

Python熊猫从列表到数据帧的类似于读取csv的功能?,python,datetime,csv,pandas,Python,Datetime,Csv,Pandas,我有一个包含如下值的列表: [['2013-04-02 19:42:00.474', '1'], ['2013-04-02 19:42:00.529', '2'], ['2013-04-02 19:42:00.543', '3'], ['2013-04-02 19:42:00.592', '4'], ['2013-04-02 19:42:16.671', '5'], ['2013-04-02 19:42:16.686', '6'], ['2013-04-02 19:42:16.708', '7'

我有一个包含如下值的列表:

[['2013-04-02 19:42:00.474', '1'],
['2013-04-02 19:42:00.529', '2'],
['2013-04-02 19:42:00.543', '3'],
['2013-04-02 19:42:00.592', '4'],
['2013-04-02 19:42:16.671', '5'],
['2013-04-02 19:42:16.686', '6'],
['2013-04-02 19:42:16.708', '7'],
['2013-04-02 19:42:16.912', '8'],
['2013-04-02 19:42:16.941', '9'],
['2013-04-02 19:42:19.721', '10'],
['2013-04-02 19:42:22.826', '11'],
['2013-04-02 19:42:25.609', '8'],
['2013-04-02 19:42:58.225', '5']]
我知道如果这是一个csv文件,我可以将它读入一个数据框,并将日期和时间戳放入索引中,使数据框成为一个时间序列

如何在不将列表保存到csv文件的情况下实现这一点

我尝试了df=pd.DataFrame(tlist,columns=['date\u time','count']),然后尝试了df=df.set\u index('date\u time'))

但索引值显示为对象,而不是时间戳:

df.index

Index([2013-04-02 19:42:00.474, 2013-04-02 19:42:00.529, 2013-04-02 19:42:00.543, ............], dtype=object)
[40]中的
:df.index=df.index.to_datetime()
In[41]:df.index
出[41]:
[2013-04-02 19:42:00.474000, ..., 2013-04-02 19:42:58.225000]
长度:13,频率:无,时区:无
[40]中的
:df.index=df.index.to_datetime()
In[41]:df.index
出[41]:
[2013-04-02 19:42:00.474000, ..., 2013-04-02 19:42:58.225000]
长度:13,频率:无,时区:无
In [40]: df.index = df.index.to_datetime()

In [41]: df.index
Out[41]: 
<class 'pandas.tseries.index.DatetimeIndex'>
[2013-04-02 19:42:00.474000, ..., 2013-04-02 19:42:58.225000]
Length: 13, Freq: None, Timezone: None