Simple tsplot for timeseries

2019-07-27 00:09发布

I have below dataframe:

    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

I want to plot a simple timeseries using seaborn. Just a line chart of count on the Y-Axis, with Date on the X-axis something like this just for example: enter image description here

I thought it would be as simple as: sns.tsplot(data=df, time=df['Date'], value=df['count']) or sns.tsplot(data=df, time='Date', value='count') and following the tsplot() documentation I can't quite get this simple line of code. The datatypes seem fine, but what am i missing here?:

#df.dtypes
Date     datetime64[ns]
group            object
count             int64

Side note, does anyone know why tsplot() is being deprecated for? (beyond the vague definition in the docs)

2条回答
Anthone
2楼-- · 2019-07-27 00:44
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")

enter image description here

However note that the answer of @ImportanceOfBeingErnest is more appropriate

查看更多
我只想做你的唯一
3楼-- · 2019-07-27 00:50

I guess tsplot is deprecated because people tend to think it would be useful for plotting timeseries - which isn't the case. Of course you may use it, see e.g. this question, but I would recommend simply plotting the data as a line plot:

ax = df.plot(x="Date", y="count")
ax.figure.autofmt_xdate()

enter image description here

查看更多
登录 后发表回答