Questions tagged [pandas-settingwithcopy-warning]
25 questions
0
votes
0 answers
SettingWithCopyWarning in Multiple Jupyter Cells when displaying dataframe
This bug took forever to isolate, and, now that I have, I don't understand why it happens.
I am working in Jupyterlab. want to import a dataset, set two its columns to be a MultiIndex, filter by one of the index dimensions, and then add a new column…

Vadim
- 3
- 2
0
votes
0 answers
Setting with copy warning... what am I doing wrong?
I've read all kinds of documentation about this warning in Pandas. Aside from getting frustrated because I still haven't seen a case where it's not absolutely clear what is trying to be done (so the warning feels like a needless complication), I'm…

NaiveBae
- 358
- 1
- 10
0
votes
1 answer
SettingWithCopyWarning using loc/iloc doesn't set values
sp_eur.iloc[72][['Open_eur','High_eur','Low_eur','Close_eur','Volume_eur','Dividends_eur','Stock Splits_eur']] = sp_eur.iloc[71][['Open_eur','High_eur','Low_eur','Close_eur','Volume_eur','Dividends_eur','Stock Splits_eur']]
returns this:
See the…

julian lagier
- 62
- 7
0
votes
0 answers
SettingWithCopyWarning while assigning value_counts()
I am trying to assign certain values to a column in a dataframe within a Python function.
df = df[(df['date'] <= max_date) & (df['date'] > min_date) | (df['x_date'] <= max_date) & (df['x_date'] > min_date)]
numbers = len(df)
…

Jnl
- 194
- 1
- 11
0
votes
1 answer
SettingWithCopyWarning Python3
I am finding the max of df2 by row, and setting the max value to new col on df1.
df1['max'] = df2[df2.keys().tolist()].max(axis=1)
This line is throwing a SettingWithCopyWarning. Not sure how to re-write it to make the warning go away. How to…

Yash
- 1
- 2
0
votes
1 answer
Getting 'A value is trying to be set on a copy of a slice from a DataFrame.' while creating a new column
I'm selecting a few rows from a dataframe as a new dataframe and trying to add a new column to that new dataframe with the selected rows. And I keep getting the warning, eventhough, I'm not trying set a value on a slice of that dataframe. The slice…

Ankhnesmerira
- 1,386
- 15
- 29
0
votes
1 answer
Python: change column month to separate quarter columns; SettingWithCopyWarning: A value is trying to be set on a copy of a slice from a DataFrame
I would like to add to my DF 4 new columns with boolean type representing quarters of the year.
I have column with month numbers and would like to get this result:
month Q1 Q2 Q3 Q4
6 0 1 0 0
7 0 0 1 0
8 0 0 1 …

Veracious
- 27
- 4
0
votes
1 answer
How to fix SettingWithCopyWarning? (Python)
I have a dataframe with some columns of the same type:
['total_tracks', 't_dur0', 't_dur1', 't_dur2', 't_dance0', 't_dance1', 't_dance2',
't_energy0', 't_energy1', 't_energy2', 't_key0', 't_key1', 't_key2', 't_mode0',
't_mode1', 't_mode2',…

Mampenda
- 661
- 4
- 21
-1
votes
1 answer
Pandas SettingWithCopyWarning is killing me
I try to filter Pandas DataFrame:
df = pd.read_csv('ml_data.csv', dtype=str)
def df_filter(df):
#df = df.copy()
df.replace('(not set)', '(none)', inplace=True) #comment this and warning will disappear!!!
df = df[df['device_browser'] !=…

Ars ML
- 49
- 4
-1
votes
1 answer
avoid SettingWithCopyWarning when using a function
I have DataFrame and I need to derivate a new column based on the value of an existing column.
class SomeClass:
def reduce(self, x):
if x < 1:
return x ** 2
return np.sqrt(x)
def penalize_performance(self, df):
…

Nicola Lepetit
- 756
- 8
- 25