Prerequisistes: Python Pandas
Pandas is mainly popular for importing and analyzing data much easier. Pandas is fast and it has high-performance & productivity for users.
In this article, we are trying to filter the data of an excel sheet and save the filtered data as a new Excel file.
Note: You can click on this filename to download this sheet datasets.xlsx
Excel Sheet used:
In this excel sheet we are having three categories in Species column-
Now our aim is to filter these data by species category and to save this filtered data in different sheets with filename =species.subcategory name i.e. after the execution of the code we will going to get three files of following names-
Below is the implementation.
- First, we have imported the Pandas library.
- Then we have loaded the data.xlsx excel file in the data object.
- To fetch the unique values from that species column we have used
unique()function. To check the unique values in the Species column we have called the unique() in speciesdata object.
- Then we will going to iterate the speciesdata object as we will going to store the Species column unique values(i.e. Setosa, Versicolor, Virginica) one by one.
- In object “a” we are filtering out the data that matches the
Species.speciesdatai.e. in each iteration object a will going to store three different types of data i.e. data of Setosa type then data of Versicolor type and at last the data of Virginica type.
- Now to save the filtered data one by one in excel file we have used to_excel function, where, the file will going to be saved by the speciesdata name.
- Working with excel files using Pandas
- Convert CSV to Excel using Pandas in Python
- Creating a dataframe using Excel files
- Python | Pandas dataframe.filter()
- Python | Pandas Series.filter()
- Python | How to copy data from one excel sheet to another
- How to Create a Pivot table with multiple indexes from an excel sheet using Pandas in Python?
- Python | Plotting charts in excel sheet with Data Tools using XlsxWriter module | Set - 1
- Python | Plotting charts in excel sheet with data tools using XlsxWriter module | Set – 2
- Python | Plotting column charts in excel sheet with data tables using XlsxWriter module
- Python | Write multiple files data to master file
- Loading Excel spreadsheet as pandas DataFrame
- Data Ingestion via Excel: Comparing runtimes
- Data profiling in Pandas using Python
- Python | Pandas Index.data
- Python | Data analysis using Pandas
- Python | Pandas Series.data
- Data Manipulattion in Python using Pandas
- Get the data type of column in Pandas - Python
- Python | Data Comparison and Selection in Pandas
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.