Skip to content

Instantly share code, notes, and snippets.

@YuheiNakasaka
Created April 11, 2017 08:05
Show Gist options
  • Save YuheiNakasaka/f6420b40b01f5e3a3bca6446e098a103 to your computer and use it in GitHub Desktop.
Save YuheiNakasaka/f6420b40b01f5e3a3bca6446e098a103 to your computer and use it in GitHub Desktop.
Aggrigate impressions per day from exported twitter analytics csv with pandas
import pandas as pd
df = pd.read_csv('tweet_activity_metrics_example_20170314_20170412_ja.csv', header=None).loc[:, [3, 4]]
df = df.drop(0)
df[3] = pd.to_datetime(df[3])
df[4] = pd.to_numeric(df[4])
result = df.groupby([df[3].dt.year, df[3].dt.month, df[3].dt.day])[4].sum()
print(result)
# date sum of impressions
# 2017 3 14 127.0
# 15 66.0
# 16 31.0
# 17 129.0
# 18 175.0
# 19 128.0
# 20 109.0
# 21 157.0
# 22 113.0
# 23 106.0
# 24 153.0
# 25 116.0
# 26 124.0
# 27 199.0
# 28 155.0
# 29 146.0
# 30 196.0
# 31 230.0
# 4 1 164.0
# 2 183.0
# 3 282.0
# 4 227.0
# 5 116.0
# 6 154.0
# 7 101.0
# 8 177.0
# 9 192.0
# 10 141.0
# 11 21.0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment