【问题标题】:Plotting a time series data绘制时间序列数据
【发布时间】:2020-04-09 13:19:53
【问题描述】:

我有一个时间序列数据,其中一列是日期,第二列是代理的 ID。

    pAgent  Date    Year    Month   Day Week-Day
0   27918   2019-11-28  2019    11  28  3
1   1286    2019-11-28  2019    11  28  3
2   1314    2019-11-28  2019    11  28  3
3   21342   2019-12-01  2019    12  1   6
4   5344    2019-11-28  2019    11  28  3
5   23841   2019-11-28  2019    11  28  3
6   22596   2019-11-28  2019    11  28  3
.   ..      ...         ..      ..  ..  ..
.   ..      ...         ..      ..  ..  ..

如何绘制一个代理的出现情况,比如 pAgent = 22596,整整一个月?

【问题讨论】:

  • 你试过什么?你的作品根本没有展出!
  • @solenya 绘制整个月的系列相对简单。 plt.figure(figsize=(14,6)) pagent_transactions.index = pagent_transactions['Date'] sns.lineplot(data=pagent_transactions['pAgent']) 我被困在为特定代理策划事件。
  • 你可以在问题中添加这个!

标签: python matplotlib data-visualization data-analysis


【解决方案1】:

你可以像这样创建甘特图,

import pandas as pd
import matplotlib.pyplot as plt 
df = pd.DataFrame({'pAgent' :[22596,22596,44456,6655,22596,22596,42244,22596,22596,22596] ,'day':  [1,2,3,4,5,6,7,8,9,10]  })
fig, axes = plt.subplots(figsize=(10, 8))
axes.scatter(df[df['pAgent'] == 22596]['day'], df[df['pAgent'] == 22596]['pAgent'], marker = '|',s=10**3)
axes.set(xlabel='days')
fig.show()

【讨论】:

    【解决方案2】:

    有一个简单的数据处理错误,我终于能够解决它。这是解决问题的方法:

    count = file_name[file_name['pAgent'] == 27918].groupby("Day").count().reset_index()
    plt.figure(figsize=(12,6))
    ax = sns.pointplot("Day","pAgent",data=count,color="white",markers="H")
    plt.axhline(avg_curr["pAgent"].mean(),color="k",
                linestyle="dotted",linewidth=2,label="average transaction flow")
    

    【讨论】:

      猜你喜欢
      • 2013-12-25
      • 2011-09-30
      • 1970-01-01
      • 2014-05-12
      • 2017-03-04
      • 2018-10-21
      • 2011-03-19
      相关资源
      最近更新 更多