creating new columns but get earning in pandas

Viewed 101

I always get this warning when I try to create a column, what can I do differently? Thank you.

A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_indexer,col_indexer] = value instead

See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
  foodie['Age'] = foodie['questions_135557_how_old_are_you']

enter image description here

2 Answers

It's a warning, not an error, but one you should handle
If you're just trying to change the names of the columns, use the rename method

foodie = foodie.rename(columns={
    'questions_135557_how_old_are_you': 'Age',
    'questions_134999_where_are_you_eating_at_the_moment': 'Location'
})

It's just a warning. If you want to hide the error put this line after the import pandas as pd line...

pd.options.mode.chained_assignment = None

If you want to see them again comment it out and restart the kernel.

Related