Open oxygenbilly opened 3 days ago
[X] I have checked that this issue has not already been reported.
[X] I have confirmed this bug exists on the latest version of pandas.
[X] I have confirmed this bug exists on the main branch of pandas.
pr = pd.period_range('2024-01-01 00:00:00', '2024-01-01 02:00:00', freq='h') df = pd.DataFrame(index=pr) df['date'] = df.index.to_timestamp().floor('D') df['hour'] = df.index.hour df.index.name = 'value' df = df.reset_index() df = df.pivot(index='date', columns='hour', values='value') print(df) # hour 0 1 2 # date # 2024-01-01 2024-01-01 00:00 2024-01-01 01:00 2024-01-01 02:00 print(df[[0,1,2]]) # hour 0 1 2 # date # 2024-01-01 2024-01-01 00:00 2024-01-01 00:00 2024-01-01 00:00
when the datatype is period[h], the slicing will not produce the correct results. if the datatype is changed to object. result is correct
The expected behavior is to slice the column properly based on hour [0, 1, 2]. However the above results give all [0] column for all of [0, 1, 2]
Thanks for the report! Confirmed on main. Further investigations and PRs to fix are welcome!
Hello, @oxygenbilly, I would like to investigate this issue, if you aren't working on it.
Pandas version checks
[X] I have checked that this issue has not already been reported.
[X] I have confirmed this bug exists on the latest version of pandas.
[X] I have confirmed this bug exists on the main branch of pandas.
Reproducible Example
Issue Description
when the datatype is period[h], the slicing will not produce the correct results. if the datatype is changed to object. result is correct
Expected Behavior
The expected behavior is to slice the column properly based on hour [0, 1, 2]. However the above results give all [0] column for all of [0, 1, 2]
Installed Versions