chained-assignment

Confusion re: pandas copy of slice of dataframe warning

旧城冷巷雨未停 提交于 2019-11-28 09:05:40
I've looked through a bunch of questions and answers related to this issue, but I'm still finding that I'm getting this copy of slice warning in places where I don't expect it. Also, it's cropping up in code that was running fine for me previously, leading me to wonder if some sort of update may be the culprit. For example, this is a set of code where all I'm doing is reading in an Excel file into a pandas DataFrame , and cutting down the set of columns included with the df[[]] syntax. izmir = pd.read_excel(filepath) izmir_lim = izmir[['Gender','Age','MC_OLD_M>=60','MC_OLD_F>=60','MC_OLD_M>18'

Checking whether data frame is copy or view in Pandas

≡放荡痞女 提交于 2019-11-28 04:55:59
Is there an easy way to check whether two data frames are different copies or views of the same underlying data that doesn't involve manipulations? I'm trying to get a grip on when each is generated, and given how idiosyncratic the rules seem to be, I'd like an easy way to test. For example, I thought "id(df.values)" would be stable across views, but they don't seem to be: # Make two data frames that are views of same data. df = pd.DataFrame([[1,2,3,4],[5,6,7,8]], index = ['row1','row2'], columns = ['a','b','c','d']) df2 = df.iloc[0:2,:] # Demonstrate they are views: df.iloc[0,0] = 99 df2.iloc

Correct way to set value on a slice in pandas [duplicate]

我与影子孤独终老i 提交于 2019-11-27 18:21:10
This question already has an answer here: How to deal with SettingWithCopyWarning in Pandas? 13 answers I have a pandas dataframe: data. it has columns ["name", 'A', 'B'] What I want to do (and works) is: d2 = data[data['name'] == 'fred'] #This gives me multiple rows d2['A'] = 0 This will set the column A on the fred rows to 0. I've also done: indexes = d2.index data['A'][indexes] = 0 However, both give me the same warning: /Users/brianp/work/cyan/venv/lib/python2.7/site-packages/pandas/core/indexing.py:128: SettingWithCopyWarning: A value is trying to be set on a copy of a slice from a

Pandas: SettingWithCopyWarning [duplicate]

这一生的挚爱 提交于 2019-11-27 12:10:14
This question already has an answer here: How to deal with SettingWithCopyWarning in Pandas? 13 answers I'd like to replace values in a Pandas DataFrame larger than an arbitrary number (100 in this case) with NaN (as values this large are indicative of a failed experiment). Previously I've used this to replace unwanted values: sve2_all[sve2_all[' Hgtot ng/l'] > 100] = np.nan However, I got the following error: -c:3: SettingWithCopyWarning: A value is trying to be set on a copy of a slice from a DataFrame. Try using .loc[row_index,col_indexer] = value instead C:\Users\AppData\Local\Enthought

Pandas: Knowing when an operation affects the original dataframe

会有一股神秘感。 提交于 2019-11-27 10:19:06
问题 I love pandas and have been using it for years and feel pretty confident I have a good handle on how to subset dataframes and deal with views vs copies appropriately (though I use a lot of assertions to be sure). I also know that there have been tons of questions about SettingWithCopyWarning, e.g. How to deal with SettingWithCopyWarning in Pandas? and some great recent guides on wrapping your head around when it happens, e.g. Understanding SettingWithCopyWarning in pandas. But I also know

Confusion re: pandas copy of slice of dataframe warning

|▌冷眼眸甩不掉的悲伤 提交于 2019-11-27 02:38:23
问题 I've looked through a bunch of questions and answers related to this issue, but I'm still finding that I'm getting this copy of slice warning in places where I don't expect it. Also, it's cropping up in code that was running fine for me previously, leading me to wonder if some sort of update may be the culprit. For example, this is a set of code where all I'm doing is reading in an Excel file into a pandas DataFrame , and cutting down the set of columns included with the df[[]] syntax. izmir

Action with pandas SettingWithCopyWarning

喜夏-厌秋 提交于 2019-11-27 02:02:29
I try to delete some column and convert some value in column with df2.drop(df2.columns[[0, 1, 3]], axis=1, inplace=True) df2['date'] = df2['date'].map(lambda x: str(x)[1:]) df2['date'] = df2['date'].str.replace(':', ' ', 1) df2['date'] = pd.to_datetime(df2['date']) and to all this string I get df2.drop(df2.columns[[0, 1, 3]], axis=1, inplace=True) C:/Users/����� �����������/Desktop/projects/youtube_log/filter.py:11: 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 What is problem there? Your df2

Checking whether data frame is copy or view in Pandas

大城市里の小女人 提交于 2019-11-27 00:35:46
问题 Is there an easy way to check whether two data frames are different copies or views of the same underlying data that doesn't involve manipulations? I'm trying to get a grip on when each is generated, and given how idiosyncratic the rules seem to be, I'd like an easy way to test. For example, I thought "id(df.values)" would be stable across views, but they don't seem to be: # Make two data frames that are views of same data. df = pd.DataFrame([[1,2,3,4],[5,6,7,8]], index = ['row1','row2'],

Correct way to set value on a slice in pandas [duplicate]

前提是你 提交于 2019-11-27 00:27:04
问题 This question already has an answer here: How to deal with SettingWithCopyWarning in Pandas? 14 answers I have a pandas dataframe: data. it has columns ["name", 'A', 'B'] What I want to do (and works) is: d2 = data[data['name'] == 'fred'] #This gives me multiple rows d2['A'] = 0 This will set the column A on the fred rows to 0. I've also done: indexes = d2.index data['A'][indexes] = 0 However, both give me the same warning: /Users/brianp/work/cyan/venv/lib/python2.7/site-packages/pandas/core

Pandas still getting SettingWithCopyWarning even after using .loc

一曲冷凌霜 提交于 2019-11-26 22:45:01
At first, I tried writing some code that looked like this: import numpy as np import pandas as pd np.random.seed(2016) train = pd.DataFrame(np.random.choice([np.nan, 1, 2], size=(10, 3)), columns=['Age', 'SibSp', 'Parch']) complete = train.dropna() complete['AgeGt15'] = complete['Age'] > 15 After getting SettingWithCopyWarning, I tried using.loc: complete.loc[:, 'AgeGt15'] = complete['Age'] > 15 complete.loc[:, 'WithFamily'] = complete['SibSp'] + complete['Parch'] > 0 However, I still get the same warning. What gives? Note: As of pandas version 0.24, is_copy is deprecated and will be removed