I have to find within a dataframe when a user registered or unregistered, for this I use the following code. Understanding that when the user appears for the first time it was a high and the inverse for the low of the same.
from curses import erasechar
import pandas as pd
df = pd.DataFrame({'Fecha': ['2022-08-29', '2022-08-30','2022-09-03', '2022-09-04','2022-09-05','2022-09-12'],'id': [20076,20076,20076,20076,20076,20076]})
df['Fecha'] = pd.to_datetime(df['Fecha'])
df = (df.set_index('Fecha')
.reindex(pd.date_range('2022-08-29', '2022-10-01', freq='D'))
.rename_axis(['Fecha'])
.fillna(0)
.reset_index())
pd.set_option('display.max_rows', None)
print(df)
The result is as follows:
My query is how I can get to this final result, showing only the data of when he was discharged and the same for discharge but not repeating day by day, since it is understood that only the date on which he was discharged is sought and the low. Having as a final result according to the example above the following output.