I have two pandas dataframes, one named df1 and another named df2:
import pandas as pd
df1 = pd.DataFrame({'PERCENTAGE': [0.35,0.1105,0.0487,0.98],})
df2 = df1.loc[df1['PERCENTAGE'] > 0.4]
I'm trying to create a new column in df2 using this code:
df2['NEW_COLUMN'] = 1 - df2['PERCENTAGE']
But I'm getting the following error:
C:\PATH:
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 caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
"""Entry point for launching an IPython kernel.
Is there a way to solve this without having to build this column directly in df1?