Listing and original listing identical Is modification
import pandas as pd
import numpy as np
df = pd.read_excel('test.xlsx')
df[' Gender '] = np.where(df[' Gender '] == 1,' male ',' Woman ')# amount to IF(F2=1,' male ',' Woman ')
df.to_excel('test02.xlsx',index=False)
Listing and original listing inequality Is new
import pandas as pd
import numpy as np
df = pd.read_excel('test.xlsx')
df[' Gender 2'] = np.where(df[' Gender '] == 1,' male ',' Woman ')# amount to IF(F2=1,' male ',' Woman ')
df.to_excel('test02.xlsx',index=False)
Ideas : First new , List again
insert(loc, column, value, allow_duplicates=False)
Where is the :
loc: Insert the index of the column . The first column is 0.
column: Give the new column a name .
value: Array of values for the new column .
allow_duplicates: Whether to allow new column names to match existing column names . The default is false .
import pandas as pd
import numpy as np
df = pd.read_excel('test.xlsx')
df.insert(1, ' Gender 2', "") # Location , listed , data
df[' Gender 2'] = np.where(df[' Gender '] == 1, ' male ', ' Woman ') # amount to IF(F2=1,' male ',' Woman ')
df.to_excel('test02.xlsx', index=False)
import pandas as pd
import numpy as np
df = pd.read_excel('test.xlsx')
# IF(F2=1,IF(B2>90,' yes ',' no '),' no ')
df[' Whether to go to the office '] = np.where(df[' Gender '] == 1, np.where(df[' mathematics '] > 90, ' yes ', ' no '), ' no ')
df.to_excel('test02.xlsx', index=False)