Here are some useful snippets that can come in handy when cleaning data with pandas. This was useful for me in completing the coursework for python data science course.
Extract a subset of columns from the dataframe based on a regular expression:
Set a column based on the value of both the current row and adjacent rows:
For this example, we define regulars to the gym as those who have gone to the gym last year at least 3 months in a row: