Skip to content

Commit

Permalink
Create TidyDataShortcuts.py
Browse files Browse the repository at this point in the history
  • Loading branch information
ajh1143 authored Jan 18, 2018
1 parent 8747c14 commit 1f1eb6b
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions TidyDataShortcuts.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import pandas as pd
import matplotlib.pyplot as plt

#Melts a pandas DataFrame
def tidy_melt(df, exclude, var, value):
df_melt = pd.melt(df, id_vars= exclude, var_name=var, value_name=value)
return df_melt

#Returns a pivot table from a tidy df
def tidy_to_pivot(df, indices, colname, valname):
df_piv = pd.pivot_table(df, index=indices, columns=colname, values=valname)
return df_piv

#Returns a standard DataFrame from a tidydata set
def tidy_to_og(tidy_df):
restored_df = tidy_df.reset_index()
return restored_df

0 comments on commit 1f1eb6b

Please sign in to comment.