python-2.7.4 windows7
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