You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In [1]: from pandas import *
In [2]: df = DataFrame({"A" : [1,2,3,4,5], "B": [3.1, 4, 5, 6, 7]})
In [3]: df[["A", "B"]]["A"] = 5 # no warning - bug?!
In [4]: df
Out[4]:
A B
0 1 3.1
1 2 4.0
2 3 5.0
3 4 6.0
4 5 7.0
In [5]: df[["A"]]["A"] = 5
C:\Anaconda\Scripts\ipython-script.py:1: 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 the caveats in the documentation: http://pandas.pydata.org/pandas-docs/stable/indexing.html#indexing-view-versus-copy
if __name__ == '__main__':
The text was updated successfully, but these errors were encountered:
import pandas as pd
index = pd.MultiIndex.from_product([["vars"], ["fruit", "color"]])
df = pd.DataFrame([["apple", "green"]], columns=index)
# No warning!
df.vars.color = "red"
# Still green!
print(df)
# No effect, but warning: A value is trying to be set on a copy of a slice ...
df.vars.color[0] = "red"
After df.vars.color = "red", color is not set to "red", and there's no warning.
This is pandas 0.15.2
The text was updated successfully, but these errors were encountered: