TL;DR: Use .loc[:, 'foo']
instead of .foo
When does pandas assign values to the view and when does it assign values to the copy?
AFAIK, pandas either returns view or copy, depending on the method you use.
You can change the original dataframe if you assign a value to the view but you can't change the original if a value is assigned to the copy.
However, below behavior confuses me. Why is assigning value to a view works with a dataframe but not with a series?
dd = pd.DataFrame([
{'a': 1, 'b': 2},
{'a': 2, 'b': 4},
{'a': 4, 'b': 3},
])
dd[dd.a == 1] = pd.DataFrame([{'a': 100, 'b': 200}]) # Assigning value works.
dd
>> a b
0 100 200
1 2 4
2 4 3
As expected, the value of the first row has been changed.
However, as seen below, assigning a value to a series doens't work, even thought the settings are identical except that I called a series.
dd = pd.DataFrame([
{'a': 1, 'b': 2},
{'a': 2, 'b': 4},
{'a': 4, 'b': 3},
])
dd[dd.a == 1].a = 1000 # Assigning value doesn't work.
dd
>> a b
0 1 2
1 2 4
2 4 3
I'm on pandas 0.19.1 though. (Cause I'm using Python 2.7)