excel - Adding Keyword with count of occurrence in sheet2 to existing excelfile from sheet1 with pandas python -
i fetching data web excel sheet using pandas & able save sheet 1, want fetch data of particular column sheet 2 of same excel want put name of keyword & number of times keyword appear in column
for example ,i have column title car manufacturer in sheet 1 & there can multiple rows different data same car manufacturer many customer can own audi,ford etc & there 6-7 columns in sheet1 & car manufacturer 1 of them . want data
manufacturer count 1. audi 100 2. ford 30 3. mercedes 25 4. xxxxx 9
in sheet 2. python code samples appreciated!
you asked similar question on adding data second excel sheet. perhaps can address there issues around to_excel()
part.
on category count, can do:
df.manufacturer.value_counts().to_frame()
to pd.series
counts
. need convert result .to_frame()
because dataframe
has to_excel()
method.
so altogether, using linked answer:
import pandas pd openpyxl import load_workbook book = load_workbook('abc.xlsx') writer = pd.excelwriter('abc.xlsx', engine='openpyxl') writer.book = book writer.sheets = dict((ws.title, ws) ws in book.worksheets) df.manufacturer.value_counts().to_frame().to_excel(writer, sheet_name='categories') writer.save()