Search⌘ K

Access and Modify DataFrames Values

Understand the nuances of accessing and modifying values within pandas DataFrames. This lesson helps you identify why the SettingWithCopyWarning appears and guides you on using .loc to safely update data without creating unwanted copies.

We'll cover the following...

Try it yourself

Try executing the code below to see the result.

Python 3.8
import pandas as pd
df = pd.DataFrame([
['Bugs', True, 72.3],
['Daffy', False, 30.7],
['Tweety', True, 23.5],
['Elmer', False, 103.9],
], columns=['Customer', 'Member', 'Amount'])
df[df['Member']]['Amount'] *= 0.9
print(df)

Explanation

The change is not reflected in df. The reason is ...