Sep-11-2019, 01:40 PM
Hi,
I have below DataFrame,
I want to add in "0th" row if the columns are STD, the modify the "0th" row as the:
original cell value +"STD:JPEG:"
and if the column is "Peak" then modify the cell value in "0th" row as:
original cell value +"Peak:JPEG:"
I use the below code, but it is adding multiple time. For example, STD is in three columns, the cell value is modifying as:
"CplSTD:JPEG:STD:JPEG:STD:JPEG:" but it should be: CplSTD:JPEG
My input data:
I have below DataFrame,
I want to add in "0th" row if the columns are STD, the modify the "0th" row as the:
original cell value +"STD:JPEG:"
and if the column is "Peak" then modify the cell value in "0th" row as:
original cell value +"Peak:JPEG:"
I use the below code, but it is adding multiple time. For example, STD is in three columns, the cell value is modifying as:
"CplSTD:JPEG:STD:JPEG:STD:JPEG:" but it should be: CplSTD:JPEG
My input data:
Name Category STD Peak Name Category Cpl BNP Regulator Power Voltage HAJ RT 44 6 12 45 34 LKO SP 4 34 33 13 122STD is merged for three columns, and Peak is merged for two columns.
import pandas as pd df=pd.read_excel(r'D:\PythonCodes\jpeginput.xlsx') df.rename( columns={'Unnamed: 3':'STD'}, inplace=True ) df.rename( columns={'Unnamed: 4':'STD'}, inplace=True ) df.rename( columns={'Unnamed: 3':'STD'}, inplace=True ) df.rename( columns={'Unnamed: 6':'Peak'}, inplace=True ) for i in range(len(list(df.columns))): if df.columns[i] == 'Name' or df.columns[i] == 'Category': print('skipped') print(df.columns[i]) elif(df.columns[i] == 'STD'): df.loc[0,df.columns[i]] = df.loc[0,df.columns[i]]+"STD:JPEG:" print(df.columns[i]) elif(df.columns[i] == 'Peak'): df.loc[0,df.columns[i]] = df.loc[0,df.columns[i]]+"Peak:JPEG:" print(df.columns[i]) else: print('skipped') print(df.columns[i])