Python 时间序列的简单tsplot
我有以下数据帧:Python 时间序列的简单tsplot,python,pandas,seaborn,Python,Pandas,Seaborn,我有以下数据帧: Date group count 0 2015-01-12 Category1 27 1 2015-01-19 Category1 2 2 2015-01-26 Category1 31 3 2015-02-02 Category1 20 4 2015-02-09 Category1 24 5 2015-02-16 Category1 16 6 2015-02-23 Category1 18
Date group count
0 2015-01-12 Category1 27
1 2015-01-19 Category1 2
2 2015-01-26 Category1 31
3 2015-02-02 Category1 20
4 2015-02-09 Category1 24
5 2015-02-16 Category1 16
6 2015-02-23 Category1 18
7 2015-03-02 Category1 15
8 2015-03-09 Category1 29
9 2015-03-16 Category1 6
10 2015-03-23 Category1 19
11 2015-03-30 Category1 27
12 2015-04-06 Category1 6
13 2015-04-07 Category1 7
14 2015-04-13 Category1 25
15 2015-04-20 Category1 9
我想使用seaborn绘制一个简单的timeseries。只是Y轴上的计数折线图,X轴上有日期,例如:
我想它会很简单:sns.tsplot(data=df,time=df['Date'],value=df['count'])
或sns.tsplot(data=df,time='Date',value='count')
,根据文档,我无法得到这行简单的代码。数据类型似乎很好,但我在这里遗漏了什么
#df.dtypes
Date datetime64[ns]
group object
count int64
旁注,有人知道为什么要使用
tsplot()
?(除了文档中模糊的定义之外)我想tsplot
是不受欢迎的,因为人们倾向于认为它对绘制时间序列很有用——事实并非如此。当然,您可以使用它,例如,请参阅,但我建议只将数据绘制为线图:
ax = df.plot(x="Date", y="count")
ax.figure.autofmt_xdate()
但是请注意,@ImportanceOfBeingErnest的答案更合适我也得出了使用
matplotlib
代替的结论。我用tnsplot
挣扎了一个小时左右。这里有没有办法使用tnsplot
或者没有?(因此遭到反对)嗯,我想有办法让草莓派尝起来像苹果派,但你为什么要这么做呢?苹果更便宜,所以就用苹果吧。除非你给我一个明确的动机,说明为什么使用tsplot
比仅仅用plot
绘制数据帧更可取,否则我认为在这个方向上花费任何努力都是不值得的。一个这样的动机是,用户希望有信心区间。哈哈,我喜欢这个评论,并同意。“明确的动机”纯粹是为了回答这个问题,如果可能的话,可以使用tsplot
。我猜这个回答回答了我的问题,答案是否定的-这样更好这样不会返回预期的输出。你这边是什么样子的?
import seaborn as sns
sns.tsplot(data=pd.Series([10,15,20,15,20,25,20,25,30,35,30,35,40,45]), color="b")