Python Forum
How to import dats from one sheet to another sheet based on Substring using python
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to import dats from one sheet to another sheet based on Substring using python
#1
My goal here is to import the data stored as DataFrame df in sheet1 based on the substring.

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.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  How to write table to different sheet in openpyxl rsearing 2 2,087 Aug-22-2022, 11:59 PM
Last Post: Pedroski55
  Split excel file and write output at specific row and set sheet position DSCA 0 1,994 May-12-2022, 07:29 PM
Last Post: DSCA
  substring function to create new column Chandan 6 2,469 Feb-14-2020, 10:11 AM
Last Post: scidam
  User Interaction with Excel sheet ShruthiLS 7 4,642 Jun-15-2018, 03:50 PM
Last Post: snippsat

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020