请考虑这个例子:
import numpy as np
import pandas as pd
df = pd.DataFrame([1,2,3,4,5], columns=["col"])
df[df["col"] == 3]["col"] = 11 # Does not work.
df["col"][df["col"] == 3] = 55 # Does work!
虽然分配的结果不同,但基础选择会产生相同的结果:
df[df["col"] == 3]["col"] # Looks like the same as
df["col"][df["col"] == 3] # this
为什么一种方式有效,另一种方式无效?