I'm trying to apply a function to a pandas dataframe, the function I wanna apply is to create a new column with 'abc' as a value. But the output is not what i'm expecting. Here's the code with the input and the output:
import pandas as pd
df = pd.read_csv("test.csv")
print(df)
# Initial Dataframe
# name age
# 0 alex 25
# 1 audrey 22
def add_one(df):
return df + 1
def create_col(df):
df["new_col"] = 'abc'
df["age_1_year"] = df["age"].apply(add_one)
df["my_col"] = df.apply(create_col)
print(df)
# name age age_1_year my_col
# 0 alex 25 26 NaN
# 1 audrey 22 23 NaN
I was expecting to have 'abc' in my column "my_col" but I got "NaN". Thanks in advance