Python Seaborn用pandas df绘制简单的时间序列

时间:2016-08-28 07:16:22

标签: python pandas matplotlib plot seaborn

我尝试使用seaborn tsplot绘制我的pandas数据帧,其中x轴为日期,y轴为点击次数。这是非常简单的情节。

这是我的数据:

"date","shown","clicked","converted","avg_cost_per_click","total_revenue","ad"
2015-10-01,65877,2339,43,0.9,641.62,"ad_group_1"
2015-10-02,65100,2498,38,0.94,756.37,"ad_group_1"
2015-10-03,70658,2313,49,0.86,970.9,"ad_group_1"
2015-10-04,69809,2833,51,1.01,907.39,"ad_group_1"
2015-10-05,68186,2696,41,1,879.45,"ad_group_1"
2015-10-06,66864,2617,46,0.98,746.48,"ad_group_1"
2015-10-07,68227,2390,42,0.94,462.33,"ad_group_1"
2015-10-08,68520,2909,46,1.07,441.28,"ad_group_1"
2015-10-09,67250,2385,49,0.88,602.14,"ad_group_1"

我的代码

import pandas as pd
import seaborn as sb
import matplotlib.pyplot as plt
df = pd.read_csv("ads.csv")
sb.tsplot(x=df.date,y=df.clicked,data=df)

我收到此错误:

ValueError: cannot label index with a null key

如果seaborn不好我不介意尝试其他包裹。 我试过matplotlib:

df.set_index(['date'],inplace=True) 
plt.figure()
df.plot()
plt.show()

但我如何只选择某些y值进行绘图?

enter image description here df.plot(df,index,df.converted)给出了一个错误:

IndexError: indices are out-of-bounds

0 个答案:

没有答案