How to properly add a single item to a series of list data type? I tried to make a copy and add an item to the list but this method affects the original dataframe instead
This is my code:
df = pd.DataFrame({'num':[['one'],['three'],['five']]})
# make copy of original df
copy_df = df.copy()
# add 'thing' to every single list
copy_df.num.apply(lambda x: x.append('thing'))
# show results of copy_df
print(copy_df) # this will show [['one', 'thing'], ['three', 'things'], ...]
print(df) # this will also show [['one', 'thing'], ['three', 'things'], ...]
# WHY?
My question is:
- why the method above adds element to original copy too?
- Is there any better way to add element to a Series of list?