Let's say I have the following pandas dataframe:
I would like to create a new column with the value of ColB and -1 * ColB. The resulting dataframe should look like this:
How can I achieve this efficiently?
CodePudding user response:
simple way:
df['ColC'] = df['ColB'].astype(str) ", " (df['ColB']*-1).astype(str)
CodePudding user response:
You Can do it like that Direct and clear way
def Test(Col1,Col2):
for i in range(len(Col1)):
yield [Col1[i],-1*Col2[i]]
z=Test(data["ColB"],data["ColB"])
data["ColC"]=list(z)