Skip to content

Instantly share code, notes, and snippets.

@fnneves
Created January 6, 2020 23:21
Show Gist options
  • Select an option

  • Save fnneves/68d1f22c8e604e5c2dfe66f4e37d2296 to your computer and use it in GitHub Desktop.

Select an option

Save fnneves/68d1f22c8e604e5c2dfe66f4e37d2296 to your computer and use it in GitHub Desktop.
def df_filter(df, string):
new = df.filter(regex=string)
return new
# Example
data = [{'2018_inc': 10, '2019_inc': 12, '2018_rev':23}, {'2018_inc':10, '2019_inc': 20, '2018_rev': 30}]
df = pd.DataFrame(data)
y_2018 = df_filter(df, '2018') # getting all columns with 2018 in their names
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment