Advertisement
Guest User

Untitled

a guest
Aug 21st, 2019
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.38 KB | None | 0 0
  1. # Lower all values
  2. df.columns = [x.lower() for x in df.columns]
  3.  
  4. # Strip out punctuation, replace spaces and lower
  5. df.columns = df.columns.str.replace("[^\w\s]", "").str.replace(" ", "_").str.lower()
  6.  
  7. # Condense multiindex columns
  8. df.columns = ["_".join(col).lower() for col in df.columns]
  9.  
  10. # Double transpose to remove bottom row for multiindex columns
  11. df.T.reset_index(1, drop=True).T
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement