chained-assignment Questions

4

Solved

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)), column...
Kilmer asked 7/8, 2016 at 0:18

25

Solved

Background I just upgraded my Pandas from 0.11 to 0.13.0rc1. Now, the application is popping out many new warnings. One of them like this: E:\FinReporter\FM_EXT.py:449: SettingWithCopyWarning: A va...

13

Solved

How do I multiply each element of a given column of my dataframe with a scalar? (I have tried looking on SO, but cannot seem to find the right solution) Doing something like: df['quantity'] *= -...
Quinze asked 17/11, 2015 at 22:17

33

Solved

I have the following indexed DataFrame with named columns and rows not- continuous numbers: a b c d 2 0.671399 0.101208 -0.181532 0.241273 3 0.446172 -0.243316 0.051767 1.577318 5 0.614758 0.07579...
Extent asked 23/9, 2012 at 19:0

3

Solved

I'm confused about the rules Pandas uses when deciding that a selection from a dataframe is a copy of the original dataframe, or a view on the original. If I have, for example, df = pd.DataFrame(np...
Hinduism asked 25/4, 2014 at 14:44

2

Solved

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 ...
Petroleum asked 8/8, 2016 at 17:45

10

Solved

I have a pandas DataFrame with 4 columns and I want to create a new DataFrame that only has three of the columns. This question is similar to: Extracting specific columns from a data frame but for ...
Wellchosen asked 8/1, 2016 at 17:34

4

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 assertio...
Irruption asked 9/1, 2018 at 17:49

8

Solved

When selecting a sub dataframe from a parent dataframe, I noticed that some programmers make a copy of the data frame using the .copy() method. For example, X = my_dataframe[features_list].copy() ...
Barye asked 28/12, 2014 at 2:22

3

Solved

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 generate...
Evin asked 12/11, 2014 at 4:5

1

Solved

I guess these two questions are related, so I'll post them together: 1.- Is it possible to put type hint in chained assignments? These two attempts failed: >>> def foo(a:int): ... b: int =...
Hymanhymen asked 15/6, 2019 at 16:3

1

I have a large block of code that is, at some point somewhere, generating a setting with copy warning in pandas (this problem). I know how to fix the problem, but I can't find what line number it ...
Pibroch asked 22/5, 2015 at 8:40

1

It's well known (and understandable) that pandas behavior is essentially unpredictable when assigning to a slice. But I'm used to being warned about it by SettingWithCopy warning. Why is the warni...
Bonaventure asked 4/9, 2016 at 22:7

4

Solved

There are countless questions about the dreaded SettingWithCopyWarning I've got a good handle on how it comes about. (Notice I said good, not great) It happens when a dataframe df is "attached" t...
Lachrymal asked 15/4, 2017 at 7:14

1

Solved

The following line of my code causes a warning : import pandas as pd s = pd.DataFrame(np.random.randint(0,100,size=(100, 4)), columns=list('ABCD')) s.loc[-1] = [5,np.nan,np.nan,6] grouped = s.gro...
Aperture asked 26/1, 2017 at 9:13

4

Solved

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...
Cortie asked 11/4, 2014 at 3:4

1

Solved

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...
Fax asked 1/7, 2016 at 13:43

1

Solved

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 ...
Cadmarr asked 15/6, 2016 at 17:0

2

Solved

Python 3.4 and Pandas 0.15.0 df is a dataframe and col1 is a column. With the code below, I'm checking for the presence of the value 10 and replacing such values with 1000. df.col1[df.col1...
Belsky asked 3/11, 2014 at 22:23

1

Solved

I have been reading this link on "Returning a view versus a copy". I do not really get how the chained assignment concept in Pandas works and how the usage of .ix(), .iloc(), or .lo...
Imperator asked 30/1, 2014 at 17:37

1

Solved

Say I have a dataframe import pandas as pd import numpy as np foo = pd.DataFrame(np.random.random((10,5))) and I create another dataframe from a subset of my data: bar = foo.iloc[3:5,1:4] doe...
Sex asked 31/7, 2013 at 2:16
1

© 2022 - 2024 — McMap. All rights reserved.