To filter a dataframe based on column name in Python using pandas library, you can use the following code:
main.py213 chars10 lines
In this example, we create a dataframe df
and filter it to only include columns 'A' and 'C' with filtered_df = df.filter(items=['A', 'C'])
. You can modify the list of column names in items to filter based on different columns. The resulting filtered dataframe is then printed to the console with print(filtered_df)
.
gistlibby LogSnag