Bottom Page

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
 How to extract data between two strings
I have input data as below,

Group	 Name	                  Rank
Group1	 ABC_YJK_02_S_2019-08-01	2
	     ABC_YMK_5_S_2019-08-01	    5
	     ABC_JKL_S_2019-08-04	    10
Group2	 BCA_POL_S_2019-08-01	    4
	     BCA_PAL_S_2019-08-01	    5
	     BCA_TYP_S_2019-08-01	    50
	     BCA_DIST_S_2019-08-01	    23
	     BCA_STA_S_2019-08-01	    3

I name column, I only want to delete everything before the first _(underline) including underline, and remove everything after _S including _S

Then I want to write the output into out.xlsx

I use the below code, but it is not working. giving below error:
TypeError: expected string or bytes-like object

import pandas as pd
import re

df = pd.read_excel('D:\pivotdata2.xlsx',sheetname='merge')


for index, row in df.iterrows():'_ (.*?)_',row)

Top Page

Messages In This Thread
How to extract data between two strings - by SriMekala - Aug-08-2019, 04:37 AM

Possibly Related Threads...
Thread Author Replies Views Last Post
  How to extract different data groups from multiple CSV files using python Rafiz 3 407 Jun-04-2019, 05:20 PM
Last Post: jefsummers
  Extract data between two dates from a .csv file using Python 2.7 sujai_banerji 1 4,613 Nov-15-2017, 09:48 PM
Last Post: snippsat
  I'm working onn below code to extract data from excel using python kiran 1 1,132 Oct-24-2017, 01:42 PM
Last Post: kiran

Forum Jump:

Users browsing this thread: 1 Guest(s)