-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a36d961
commit 82ff4a8
Showing
2 changed files
with
64 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import sys | ||
import pandas as pd | ||
import matplotlib.pyplot as plt | ||
|
||
# load all input files into array of dataframes | ||
data = [] | ||
for j, element in enumerate(sys.argv[1:]): | ||
data.append(pd.read_csv(element)) | ||
data[j].set_index('Person',inplace=True) | ||
input = element | ||
if input.endswith('.csv'): | ||
input = input[:-4] | ||
data[j] = data[j].T | ||
data[j].insert(loc=1, column='TimeSeries', value=input) | ||
|
||
# merge dataframes, change cells to numeric, not objects | ||
df = pd.concat(data, axis=0, join='inner') | ||
df = pd.concat([df.ix[:,:2], df.ix[:,2:].apply(pd.to_numeric)], axis=1) | ||
df['Group'] = df['Group'].astype(int) | ||
|
||
# move groups and timeseries to first columns | ||
cols = list(df) | ||
cols.insert(0, cols.pop(cols.index('Group'))) | ||
cols.insert(0, cols.pop(cols.index('TimeSeries'))) | ||
df = df.ix[:, cols] | ||
|
||
# plotting | ||
for column in df.ix[:,2:]: | ||
fig, ax = plt.subplots() | ||
labels = [] | ||
for key, grp in df.groupby(['TimeSeries', 'Group'])[[column]].median().groupby(['TimeSeries']): | ||
ax = grp.reset_index().plot(ax=ax, x='Group', y=column, xticks=grp.reset_index()['Group'], kind='line', title=column) | ||
labels.append(key) | ||
lines, _ = ax.get_legend_handles_labels() | ||
ax.legend(lines, labels, loc='best') | ||
plt.savefig('fig/'+column+'.png') | ||
plt.clf() | ||
|
||
df.to_csv('test.csv') |