Sep-05-2018, 01:49 PM
My goal here is to import the data stored as DataFrame df in sheet1 based on the substring.
My DataFrame looks like below:
Any suggestion would be appreciated.
My DataFrame looks like below:
Output:df:[2 x 8]
ordercode quantity
PMC11-AA1L1FAVWJA 20
PMC21-AA1A1CBVXJA 10
PMP11-AA1L1FAWJJ 5
PMP21-AA1A1FBWJJ 3
PMP23-AA1A1FA3EJ+JA 1
PTP31B-AA3D1HGBVXJ 1
PTC31B-AA3D1CGBWBJA 2
PTP33B-AA3D1HGB1JJ 10
my desired result should be like Output:Sheet2_df2:"1C"
ordercode quantity
PMC21-AA1A1CBVXJA 10
PTC31B-AA3D1CGBWBJA 2
Sheet3_df3:"1F"
PMP11-AA1L1FAWJJ 5
PMP21-AA1A1FBWJJ 3
PMC11-AA1L1FAVWJA 20
import pandas as pd file="file.xlxs" print(data.sheet_names) data=data.parse("orders") substrings = ['1C', '1F'] d = {x: df[df['ordercode'].str.contains(x, na=False, regex=False)] for x in substrings] for k, v in d.items(): v.to_excel(f'{k}.xlsx', index=False)this code creating new Excel file. I need to store the data in same Excel file in different Sheets.
Any suggestion would be appreciated.