There are two parts to your question: (1) how to make a presentation (see the bottom of this answer) and (2) how to make a copy.
I will demonstrate some examples of data:
import pandas as pd df = pd.DataFrame([[1,2,3],[4,5,6],[None,10,20],[7,8,9]], columns=['x','y','z'])
How to make a copy: One option is to explicitly copy your DataFrame after any operations that you perform. For example, suppose we select strings that do not have NaN:
df2 = df[~df['x'].isnull()] df2 = df2.copy()
Then, if you change the values ββin df2, you will find that the changes do not apply to the original data (df) and that Pandas does not warn that "The value is trying to set the slice from the DataFrame on the copy"
df2['x'] *= 100
Note. You can get a performance hit by explicitly making a copy.
How to ignore warnings: Alternatively, in some cases you may not care if the view or copy is returned, because you intend to constantly change the data and never return to the original data. In this case, you can suppress the warning and have fun on your way (just do not forget that you disabled it and that the source data may or may not have been changed by your code, since df2 may or may not be a copy):
pd.options.mode.chained_assignment = None
For more information, see the answers to How to deal with SettingWithCopyWarning in Pandas?
How to pretend: Pandas will implicitly create views everywhere and whenever possible. The key to this is to use the df.loc[row_indexer,col_indexer] method df.loc[row_indexer,col_indexer] . For example, to multiply the values ββof column y by 100 only for rows where column x not equal to zero, we will write:
mask = ~df['x'].isnull() df.loc[mask, 'y'] *= 100