使用来自 csv 文件的 Pandas 进行地震绘图

Earthquake Plotting using Pandas, from csv file

我是 anaconda 包的新手 python。我必须绘制地震数据。我在 google 上读到 pandas 使用 matplotlib 和 csv。以下是数据。

time,mag,magType
2015-02-19T06:32:52.870Z,0.74,ml
2015-02-19T06:07:17.510Z,0.55,md
2015-02-19T06:07:03.720Z,1.01,md
2015-02-19T06:03:26.070Z,4.6,mb
2015-02-19T05:59:25.840Z,1.44,ml
2015-02-19T05:55:55.000Z,1.6,ml
2015-02-19T05:52:43.880Z,0.57,md
2015-02-19T05:45:01.820Z,0.71,ml
2015-02-19T05:39:25.430Z,0.41,ml

我需要将 2015-02-19T05:39:25.430Z 转换为类似于 2015-02-19 05:39:25 的日期时间格式,并将它们绘制在图表上。我想使用的图表类型是折线图。

要求 - - 绘制时间与幅度图 - 在图表上绘制每周出现的总次数,其中每次出现的幅度 > 2

您必须准确定义您想要的内容,但只需读取 csv 并传递参数 parse_dates=[0] and index_col=[0] 将生成一个以您的日期时间为索引的 df,dtype datetime64,然后我们可以调用 plot关于这个:

df = pd.read_csv(r'c:\data\earthquake.csv', parse_dates=[0], index_col=[0])

df.plot()