Aug-08-2019, 04:37 AM
Hi,
I have input data as below,
input.xlsx:
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
I have input data as below,
input.xlsx:
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 3I 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') #df['Group']=df['Group'].fillna(method='ffill') df.to_excel('D:\writepivotdata.xlsx',index=False) result=[] for index, row in df.iterrows(): result_tmp=re.search('_ (.*?)_',row) result.append(result_tmp)