Extracting/deleting rows from time series without using index information
Question:
I have a simple problem. I want to get a subset of time series with a certain condition that is not dependent on time index. I have a very huge dataset, I am just giving a small example to make my problem understandable.
row_num
marks
2016-01-01
1
99
2016-01-02
2
98
2016-01-01
3
95
2016-01-01
4
90
2016-01-02
5
40
2016-01-03
6
80
2016-01-04
7
20
but my problem is when I try to drop, it always drops by index and delete all index of 2016-01-01 and 2016-01-02.
I can not manually extract such a subset because data size is very huge and there are so many duplicate indices. How to solve this problem?
Answers:
Try using the following:
df[~df['row_num'].isin([1,5])]
Output:
row_num marks
2016-01-02 2 98
2016-01-01 3 95
2016-01-01 4 90
2016-01-03 6 80
2016-01-04 7 20
I have a simple problem. I want to get a subset of time series with a certain condition that is not dependent on time index. I have a very huge dataset, I am just giving a small example to make my problem understandable.
row_num | marks | |
---|---|---|
2016-01-01 | 1 | 99 |
2016-01-02 | 2 | 98 |
2016-01-01 | 3 | 95 |
2016-01-01 | 4 | 90 |
2016-01-02 | 5 | 40 |
2016-01-03 | 6 | 80 |
2016-01-04 | 7 | 20 |
but my problem is when I try to drop, it always drops by index and delete all index of 2016-01-01 and 2016-01-02.
I can not manually extract such a subset because data size is very huge and there are so many duplicate indices. How to solve this problem?
Try using the following:
df[~df['row_num'].isin([1,5])]
Output:
row_num marks
2016-01-02 2 98
2016-01-01 3 95
2016-01-01 4 90
2016-01-03 6 80
2016-01-04 7 20