[PYTHON] Use Pandas to write only the specified lines of the data frame to an excel file

Operating environment

python-2.7.4 windows7

Method

test.py


#coding:utf-8
#Import pandas as pd
import pandas as pd
#Excel file path to read
input_path = "input.xlsx"
#Excel file path to write
output_path = "output.xlsx"

#Read excel file in data frame type with pandas
data = pd.read_excel(data_path, sheetname = 'Sheet1')
#Select only specified lines(For string match)
specified_line_data = data.where(data.Result.str.contains("String")).dropna(axis=0)
#Select only specified lines(Click here for numerical match)
#specified_line_data = data.where(data.Result ==Numbers).dropna(axis=0)
#Use Excel Writer, a pandas module, to write to Excel
writer = pd.ExcelWriter(output_path)
#Write to excel file
specified_line_data.to_excel(writer, sheet_name = 'output_data')
#Save the written information
writer.save()

This time, I came up with a method to write only the specified line from the read data to another Excel file. (Specifically, only those whose Result column character string matches ("character string") are extracted)

(Note that the first line is recognized as a header when reading a file with pandas. This time, the header information (Test, Label, Result, Score, Class, Morpheme) is described in the first line of the read file. Because it was done, header processing is not performed programmatically.)

Recommended Posts

Use Pandas to write only the specified lines of the data frame to an excel file
Change the data frame of pandas purchase data (id x product) to a dictionary
Output the specified table of Oracle database in Python to Excel for each file
Try to operate an Excel file using Python (Pandas / XlsxWriter) ①
Try to operate an Excel file using Python (Pandas / XlsxWriter) ②
I want to use only the normalization process of SudachiPy
[Python] How to output a pandas table to an excel file
How to get an overview of your data in Pandas
How to read an Excel file (.xlsx) with Pandas [Python]
How to paste a CSV file into an Excel file using Pandas
I tried to open the latest data of the Excel file managed by date in the folder with Python
Let's use Python to represent the frequency of binary data contained in a data frame in a single bar graph.
[Python] How to make the file name of the output data unique (use year, month, day, hour, second)
Open an Excel file in Python and color the map of Japan
[Python] Summary of how to use pandas
Use pandas to convert grid data to row-holding (?) Data
[Pandas recommendation] An example of dividing an Excel sheet with hundreds of thousands of lines into n CSVs and assigning serial numbers to each file from 1.
How to save the feature point information of an image in a file and use it for matching
I want to display only different lines of a text file with diff
Find the index of items that match the conditions in the pandas data frame / series
Use Pillow to make the image transparent and overlay only part of it
Save an array of numpy to a wav file using the wave module
Use PIL in Python to extract only the data you want from Exif
An introduction to data analysis using Python-To increase the number of video views-
[Python] How to read excel file with pandas
Use decorators to prevent re-execution of data processing
Recursively search the specified directory to see the file
Reading, summarizing, visualizing, and exporting time series data to an Excel file with Python
I made a program in Python that changes the 1-minute data of FX to an arbitrary time frame (1 hour frame, etc.)
Template of python script to read the contents of the file
I want to give a group_id to a pandas data frame
Write data to KINTONE using the Python requests module
Let's use the open data of "Mamebus" in Python
Set the specified column of QTableWidget to ReadOnly StyledItemDelegate
Type after reading an excel file with pandas read_excel
Changed the default style (CSS) of pandas data frame output by display in Google Colab
How to create a new file when the specified file does not exist — write if the file exists
How to calculate the sum or average of time series csv data in an instant