以下任务有何不同之处?
但是
为什么我要期望第一个行为不同于第二个?
df.loc[rows, [col]] = ...
df.loc[rows, col] = ...
例如:
r = pd.DataFrame({"response": [1,1,1],},index = [1,2,3] )
df = pd.DataFrame({"x": [999,99,9],}, index = [3,4,5] )
df = pd.merge(df, r, how="left", left_index=True, right_index=True)
df.loc[df["response"].isnull(), "response"] = 0
print df
x response
3 999 0.0
4 99 0.0
5 9 0.0
但是
df.loc[df["response"].isnull(), ["response"]] = 0
print df
x response
3 999 1.0
4 99 0.0
5 9 0.0
为什么我要期望第一个行为不同于第二个?