I have a Dataframe like that :
Date Tic CLose
0 01/03/2022 AAPL 34.08
1 01/03/2022 HD 22.05
2 02/03/2022 AAPL 39.43
3 02/03/2022 HD 55.45
and I'd like to make rows with the same date to have the same index number like that :
Desired Output :
Date Tic CLose
0 01/03/2022 AAPL 34.08
0 01/03/2022 HD 22.05
1 02/03/2022 AAPL 39.43
1 02/03/2022 HD 55.45
CodePudding user response:
Let's do factorize
to encode the Date
values then update the index:
df.index = df['Date'].factorize(sort=True)[0]
Date Tic CLose
0 01/03/2022 AAPL 34.08
0 01/03/2022 HD 22.05
1 02/03/2022 AAPL 39.43
1 02/03/2022 HD 55.45