I have a long data set and need to import data into a dataframe until a specific row.
| Time | data |
|---|---|
| 08:00 | 12 |
| 09:00 | 34 |
| 10:00 | 23 |
| 08-10 | 45 |
| 11:00 | 56 |
| 12:00 | 23 |
I need to get the data when importing the excel file until Time=08-10 and igonre all other rows
| Time | data |
|---|---|
| 08:00 | 12 |
| 09:00 | 34 |
| 10:00 | 23 |
| 08-10 | 45 |
That is what I am trying to use:
data=pd.read_excel("2019-data.xls",sheet_name="110", header=4)
However, I have different sheets in which the location of the "08-10" row vary and I am not sure how to address this issue.
Thanks!
CodePudding user response:
Use Series.shift, comapre by value and then Series.cummax, invert mask and filter by boolean indexing:
df = df[~df['Time'].shift().eq('08-10').cummax()]
print (df)
Time data
0 08:00 12
1 09:00 34
2 10:00 23
3 08-10 45
