import pandas as pd import numpy as np import matplotlib.pyplot as plt # read in the csv file and put into dataframe df = pd.read_csv('/Users/joconnor/Desktop/Me/performance_feb_6_19.csv') # isolate all tests run week of Jan 28 week_1 = df['date'] < '2019-02-02' # run groupby over each action within week_1 grouped_week_1 = df[week_1].groupby(['action'], as_index=False).duration.mean() # give a name to timeframe of measurement named_week_1 = grouped_week_1.rename(columns={'duration': 'Jan 28'}) # rinse and repeat, isolate and get the mean of all actions week of Feb 4 week_2 = df['date'].between('2019-02-02', '2019-02-09') grouped_week_2 = df[week_2].groupby('action', as_index=False).duration.mean() named_week_2 = grouped_week_2.rename(columns={'duration': 'Feb 4'}) # combine each week into a single dataframe combined_view = pd.merge(named_week_1, named_week_2, on='action', how='right') # find difference to calculate change in performance times combined_view['diff'] = combined_view['Jan 28'] - combined_view['Feb 4'] print(combined_view) # export into a csv. this saves to the same folder. combined_view.to_csv('file_name.csv', sep='\t', encoding='utf-8', index=False)