-
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
Showing
1 changed file
with
17 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
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 |