dimanche 23 mai 2021

How to add a new column to a dataframe using a list with string values which users can add?

How to add a new column to a dataframe using a string in a list?

add_column['newcol']

if add_column:
   df= df.loc[:,add_column]='new column'
   print("new column added")
else:
    print("no new column added")

At the moment the error is str object doesnt contain attribute loc. Is there another pandas function which can be used to achieve this?

Aucun commentaire:

Enregistrer un commentaire