drop rows from pandas not containing ONLY a number
Find the unique values of the column. Assign them to a list, then drop them off of a copy and work with that data frame. I'm new to this so I hope this helps.
drop_columns = ['metric', '40 day metric', 'etc']
df_copy.drop(drop_columns, axis=1)
I have a pd.DataFrame created by parsing a large number of excel spreadsheets (too many to reformat them manually) and one of my columns should contain only numbers but in this case also contains some reference information at the end in the form of strings.
Ex: df['column1'] = ["12", "83", "1", "Metric", "40 Day Metric"]
I want to drop all of the columns that contain non-numeric values (in this case metric and 40 day metric). I tried ascii comparison:
df.drop(df[df['column1'] > ":"].index, inplace=True)
This gets rid of "Metric" but not "40 Day Metric" because it starts with a number. My next thought was to try to sort based on length (none of the numbers are more than 2 digits) but I got the error that series didn't have a length attribute.
Any suggestions?