-
Notifications
You must be signed in to change notification settings - Fork 173
Clean names multiindex #11
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Clean names multiindex #11
Conversation
.replace('.', '_') | ||
) | ||
|
||
df = df.rename(columns=lambda x: re.sub('_+', '_', x)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great stuff!
df = pd.DataFrame(data) | ||
return df | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wonderful, thanks for following the programming pattern!
labels = [[0, 1, 2], [0, 1, 2]] | ||
|
||
expected_columns = pd.MultiIndex(levels=levels, labels=labels) | ||
assert set(df.columns) == set(expected_columns) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wow, you really went above-and-beyond here! Thanks for doing this!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks - My only thought on this was, should we be handling levels
, labels
and maybe expected_columns
at a global level so that I am not just repeating the setup of variables? I am not experienced with writing test so I am not sure what is good or standard practice.
Thanks for your contribution, @JoshuaC3! I am going to merge. |
Thank you for the positive feedback. I learnt a lot contributing here. There are some other parts I that I think could be improved. I will raise some issues for them. |
Change
cleaan_names
so that it works for MultiIndexes and also add tests for this.Fixes #10