Skip to content
Advertisement

Select specific rows from pivot table in pandas

I have a dataframe which I pivoted and I now want to select spefici rows from the data. I have seen similar questions such as the one here: Selecting columns in a pandas pivot table based on specific row value?. In my case I want to return all the columns but I want to select only specific rows.

JavaScript

I have done the below to generate the below output

JavaScript

Generated output

JavaScript

I want to select e.g., only the data for 2008-03-01 00:00:00, 2008-03-01 01:15:00, and 2008-03-02 01:00:00.

Expected output

JavaScript

How can I do that

Advertisement

Answer

Use list of datetimes converted by to_datetime and select by DataFrame.loc:

JavaScript
User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement