CSV中的Pandas和python datetime时间戳

DHBI

我有一个潮汐数据的csv文件,其中没有收集数据的空隙。看起来像这样:

    datetime,tidal_water_level
    2014-05-13 00:00:00,0.008
    2014-05-13 01:00:00,-0.283
    2014-05-13 02:00:00,-0.491
    2014-05-13 03:00:00,-0.557
    ...

等等

我将其加载到数据帧中的开场白是:

    import matplotlib.pyplot as plt
    import datetime as dt

    headers = ['timestamp', 'tide_height']
    dtypes = [dt.datetime, float] 
    df = pd.read_csv('tides_clean.csv', names=headers, dtype=dtypes, header=1, parse_dates=True)

我从其他各种示例中总结了这些内容。它抱怨说dt.datetime不被理解。

如果我删除dtype参数,则它看起来像这样:

    df
    Out[103]: 
                    timestamp  tide_height
    0     2014-05-13 01:00:00       -0.283
    1     2014-05-13 02:00:00       -0.491
    2     2014-05-13 03:00:00       -0.557
    ...

请问如何将时间序列数据本身作为日期时间类型而不是索引进行处理?例如,绘制时间与潮汐,而不是索引与潮汐

我尝试:plt.scatter(x = df.timestamp,y = df.tide_height)并得到一个空的1.0 x 1.0方形图,外加一个错误,因此:ValueError:第一个参数必须是一个序列

我的最终目标是将数据重新采样到不同的采样频率,但这似乎是我的第一个障碍。

关闭

您只需要这样做,pandas就可以理解数据类型:

import pandas as pd

df = pd.read_csv('df.csv', parse_dates = True, index_col = 0)

然后,df.plot()您将获得一个时间序列图,其中时间在x轴上。如果您希望将索引作为日期时间对象进行访问,则可以执行

df.index.to_pydatetime()

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

PHP DateTime和时间戳计算

来自分类Dev

更新datetime2中的时间戳

来自分类Dev

使用csv模块和datetime模块解析时间戳

来自分类Dev

时间戳字符串(Unix时间)到datetime或pandas。

来自分类Dev

在多行中访问pandas datetime时间戳的值-语法?

来自分类Dev

sqlite比较时间戳和C#中的DateTime

来自分类Dev

TypeError串联时间戳和'datetime.time'

来自分类Dev

从python的datetime获取时间戳(以秒为单位)

来自分类Dev

使用Python将DateTime时间戳转换为Unix

来自分类Dev

Python为什么pd.to_datetime返回时间戳格式?

来自分类Dev

使用Python将DateTime时间戳转换为Unix

来自分类Dev

将时间戳转换为_datetime() 并按年和月、Pandas、Python 聚合

来自分类Dev

如何在云时间和本地时间之间转换 Google API DateTime 时间戳

来自分类Dev

MySQL将时间戳和时间字符串转换为DateTime格式

来自分类Dev

MySQL中时间戳的datetime,date和time字段的值不同

来自分类Dev

为什么我从时间戳获取不同的结果(datetime.datetime与pandas.Series datetime64)?

来自分类Dev

在Python中,如何仅使用datetime包获取本地化的时间戳?

来自分类Dev

将特定时区的datetime转换为python中的unix时间戳

来自分类Dev

在Python中,如何仅使用datetime包获取本地化的时间戳?

来自分类Dev

使用 DateTime python 3.5 计算 UTC +0 中的午夜时间戳

来自分类Dev

pandas.to_datetime()如何从本地时区转换为UTC Unix时间戳?

来自分类Dev

从今天开始的PHP DateTime和时间戳不相同

来自分类Dev

Python Pandas ix时间戳

来自分类Dev

水星和时间戳

来自分类Dev

如何将API时间戳转换为python datetime对象

来自分类Dev

为什么我的python datetime对象(从时间戳创建)没有自动创建为UTC?

来自分类Dev

如何将API时间戳转换为python datetime对象

来自分类Dev

如何将JSON时间戳(μs)反序列化为JSON中的DateTime?

来自分类Dev

mysql时间戳的Joda-Time日期格式中的当前datetime

Related 相关文章

  1. 1

    PHP DateTime和时间戳计算

  2. 2

    更新datetime2中的时间戳

  3. 3

    使用csv模块和datetime模块解析时间戳

  4. 4

    时间戳字符串(Unix时间)到datetime或pandas。

  5. 5

    在多行中访问pandas datetime时间戳的值-语法?

  6. 6

    sqlite比较时间戳和C#中的DateTime

  7. 7

    TypeError串联时间戳和'datetime.time'

  8. 8

    从python的datetime获取时间戳(以秒为单位)

  9. 9

    使用Python将DateTime时间戳转换为Unix

  10. 10

    Python为什么pd.to_datetime返回时间戳格式?

  11. 11

    使用Python将DateTime时间戳转换为Unix

  12. 12

    将时间戳转换为_datetime() 并按年和月、Pandas、Python 聚合

  13. 13

    如何在云时间和本地时间之间转换 Google API DateTime 时间戳

  14. 14

    MySQL将时间戳和时间字符串转换为DateTime格式

  15. 15

    MySQL中时间戳的datetime,date和time字段的值不同

  16. 16

    为什么我从时间戳获取不同的结果(datetime.datetime与pandas.Series datetime64)?

  17. 17

    在Python中,如何仅使用datetime包获取本地化的时间戳?

  18. 18

    将特定时区的datetime转换为python中的unix时间戳

  19. 19

    在Python中,如何仅使用datetime包获取本地化的时间戳?

  20. 20

    使用 DateTime python 3.5 计算 UTC +0 中的午夜时间戳

  21. 21

    pandas.to_datetime()如何从本地时区转换为UTC Unix时间戳?

  22. 22

    从今天开始的PHP DateTime和时间戳不相同

  23. 23

    Python Pandas ix时间戳

  24. 24

    水星和时间戳

  25. 25

    如何将API时间戳转换为python datetime对象

  26. 26

    为什么我的python datetime对象(从时间戳创建)没有自动创建为UTC?

  27. 27

    如何将API时间戳转换为python datetime对象

  28. 28

    如何将JSON时间戳(μs)反序列化为JSON中的DateTime?

  29. 29

    mysql时间戳的Joda-Time日期格式中的当前datetime

热门标签

归档