In [2]:
import pandas as pd
import numpy as np
import csv
%pylab inline
from matplotlib import pyplot
In [3]:
df = pd.read_csv('~/Downloads/all-content.csv')
In [4]:
df.tail()
Out[4]:
In [56]:
df2 = df[["Audience Targeting","Lifetime Post Total Reach","Lifetime Post organic reach", "Lifetime Engaged Users"]]
In [57]:
df2["Count"] = 1
df2.head()
Out[57]:
I need to resample the dataset, but to do that I think I need to set the Posted as the index?
In [39]:
df2_pivoted = pd.pivot_table(
df2,
["Lifetime Post Total Reach","Lifetime Post organic reach","Lifetime Engaged Users","Count"],
aggfunc = np.sum)
In [71]:
df2_resampled = df2.resample('W,',how='sum')
In [72]:
df2_resampled.tail()
Out[72]:
In [73]:
df2_resampled["Average Reach"] = df2_resampled["Lifetime Post Total Reach"]/df2_resampled["Count"]
In [74]:
df2_resampled.tail()
Out[74]:
In [131]:
df2_resampled.plot(y="Average Reach",kind='line',title="Mean Post Reach")
df2_resampled.plot(y="Lifetime Post Total Reach",kind='line')
df2_resampled["Average Organic Reach"] = df2_resampled["Lifetime Post organic reach"] / df2_resampled["Count"]
df2_resampled.plot(y="Average Organic Reach")
Out[131]:
In [69]:
df2_resampled
Out[69]:
In [76]:
df3_resampled = df2.resample('W,',how='median')
In [130]:
df3_resampled.plot(y="Lifetime Post Total Reach", title = "Median Post Reach")
Out[130]:
In [111]:
df2["Targeted"] = pd.Series(df2["Audience Targeting"]) != " "
In [113]:
df2.Targeted = df2.Targeted.astype(int)
In [115]:
df2["Targeted"].corr(df2["Lifetime Post Total Reach"])
Out[115]:
In [117]:
df2_pivoted = pd.pivot_table(df2,values = ["Lifetime Post Total Reach","Count"],index=["Targeted"],aggfunc=np.sum)
In [118]:
df2_pivoted
Out[118]:
In [119]:
df2_pivoted["Average Reach"] = df2_pivoted["Lifetime Post Total Reach"] / df2_pivoted["Count"]
In [120]:
df2_pivoted
Out[120]:
In [126]:
df2_recent = df2[:230]
In [127]:
df2_recent["Targeted"] = pd.Series(df2_recent["Audience Targeting"]) != " "
df2_recent.Targeted = df2_recent.Targeted.astype(int)
df2_pivoted = pd.pivot_table(df2_recent,values = ["Lifetime Post Total Reach","Count"],index=["Targeted"],aggfunc=np.sum)
df2_pivoted["Average Reach"] = df2_pivoted["Lifetime Post Total Reach"] / df2_pivoted["Count"]
In [128]:
df2_pivoted
Out[128]:
In [129]:
df2_pivoted.plot(y="Average Reach",kind='bar')
Out[129]:
In [ ]: