Need a suggestion in my code.
I have a data frame in sheet1 of workbook:
column 1 column 2
000A0000 2
000B0000 3
000A0001 5
000B0001 1
My desired result:
in sheet 2 of Workbook:
column 1 column 2
000A0000 2
000A0001 5
In sheet 3 of Workbook:
column 1 column 2
000B0000 3
000B0001 1
I have done my coding:
import pandas as pd
file="workbook.xlxs"
print(data.sheet_names)
data=data.parse("sheet1")
substrings = ['A', 'B']
T = {x: df[df['sheet1'].str.contains(x, na=False, regex=False)] for x in substrings]
for key, var in T.items():
var.to_excel(f'{key}.xlsx', index=False)
by this I can create new workbook. But I need to create new worksheet in same workbook.
Any suggestion would be appreciated.