Question:
Sort and filter on excel column using python?

Problem:

I have an Excel file that has multiple columns. and some of the columns have filter (dropdowns with multiple selections). I want to make excel files based on columns like this : columns: x , y , z , t , date, hour note: in columns DATE and HOUR we multiple selection. for example, column HOUR has filters like 00:00, 1:00, 2:00 , 3:00, 4:00 and ..........

what I am looking for is creating new Excel files based on the rows with these conditions: 

newExcel1: date 1, hour 00:00


newexcel2: date 1, hour 1:00


newExcel3: date 1: hour 2:00


...............................


newExcel24:day 1 hour 23:00


newExcel25: day 2 hour 00:00



Solution: 

Try a loop on the Day-Hour column with group by:


# Read your excel file

df = pd.read_excel('data.xlsx')


# Postprocessing here (rename columns, etc)

...


# Export data in multiple files

for idx, (ts, subdf) in enumerate(df.groupby('Day-Hour'), 1):

    subdf.to_excel(f'newExcel{idx}.xlsx', index=False)



Suggested blogs:

>Build a minimal ASP.Net Core API with Android Studio for Mac

>Complete guide on Life Cycle of Angular Component

>Complete guide to Perform crud operation in angular using modal popup

>Create a Vue.js application with CLI Services

>Creating API in Python using Flask

>CRUD Operation on Angular

>CRUD Operations In ASP.NET Core Using Entity Framework Core Code First with Angularjs

>Deploying a python App for iOS, Windows, and macOS

>Design a basic Mobile App With the Kivy Python Framework

>How React hooks Completely replace redux?


Ritu Singh

Ritu Singh

Submit
0 Answers