Reputation: 8957
I wanted to drop remaining rows on pandas dataframe when the specific column value has that value.
For example, if the col1 has value as "FEB", drop remaining all rows including that row.
Code:
df = pd.read_excel(path, usecols=range(32, 89), skiprows=9).dropna(how='all')
Upvotes: 0
Views: 164
Reputation: 1
Try invert (~) operator:
df=df[~df['col1'].str.match('FEB')]
to select number, you can directly use:
new_dataframe=df[df.col1 != #put number here]
Upvotes: 0
Reputation: 150735
you can also use cumsum
:
df = df[df['col1'].eq('FEB').cumsum().eq(0)]
Test data:
df = pd.DataFrame({'col1': ['JAN', 'MAY', 'FEB', 'JAN', 'FEB'],
'col2': [1,2,3,4,5]})
col1 col2
0 JAN 1
1 MAY 2
2 FEB 3
3 JAN 4
4 FEB 5
output:
col1 col2
0 JAN 1
1 MAY 2
Upvotes: 1
Reputation: 323226
In your case using argmax
yourdf=df.iloc[:df.col1.eq('FEB').values.argmax(),:].copy()
Upvotes: 1