I have a dataframe like the one below, where I have a daily count of points for each team. However, it’s a tough task to earn points and on many days the points stay the same. Since I’m turning the dataframe into a chart, I want to remove the rows where the point values are the same as that of the previous day. So in this case we keep row 0, row 1 is the same so we omit it, then keep row 2 because it’s different from row 1.
row | date | Team A | Team B |
---|---|---|---|
0 | 07-01-24 | 2pts | 2pts |
1 | 07-02-24 | 2pts | 2pts |
2 | 07-03-24 | 4pts | 2pts |
And of course, we don’t want to compare the date. The idea for what I want to accomplish is something like this, but keeping it as a dataframe:
df = [
df.iloc[[i]] for i in df.index[1:]
if
any(df.iloc[:, 1:].iloc[[i]] != df.iloc[:, 1:].shift(1).iloc[[i]])
]
720 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.