I am trying to remove rows from a pandas df. Specifically, I want to keep everything the first string in Col A finishes in. So, for the df below, the string finishes with Mon so I want to remove any rows that don't finish with this value.
import pandas as pd
df = pd.DataFrame({
'Col 1' : ['val1-Mon','val2-Mon','val3-Tues','val4-Tues','val5-Mon','val6-Mon','val7-Mon','val8-Mon'],
'Col 2' : ['A','B','A','B','A','B','A','B'],
})
This is easy enough for the df above by using the following.
df = df[~df['Col 1'].str.contains("Tues")]
But my input data changes every day. While I want to keep all Mon values today, I may want Tues values tomorrow. So I'd have to go in and manually update the day I didn't want.
The consistency is that first value. So if it ends in Mon, I want to keep everything ending in Mon. If the first row ends in Tues, I want to keep everything ending in Tues ect.