Screen Link:
My Code:
bool_map = {'Yes': True, 'No': False}
for col in [
"Have you seen any of the 6 films in the Star Wars franchise?",
"Do you consider yourself to be a fan of the Star Wars film franchise?"
]:
star_wars[col] = star_wars[col].map(bool_map)
What I expected to happen:
df.map()
function to work and values in the dataframe to be replaced accordingly
What actually happened:
/dataquest/system/env/python3/lib/python3.4/site-packages/ipykernel/__main__.py:5: SettingWithCopyWarning:
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: http://pandas.pydata.org/pandas-docs/stable/indexing.html#indexing-view-versus-copy
To be clear, the map did work, but it still throws this warning. I’ve read the DQ blog post on SettingWithCopyWarning and have researched elsewhere online, and I can’t find the fix. I’ve tried to append .copy()
to the end of my code but this doesn’t work either. I’ve also tried star_wars.loc[:, col] = star_wars.loc[:, col].map(bool_map)
with the same result.
To make things more confusing, the solution set uses my exact same method!
Thanks in advance.