Skip to content
Advertisement

how to clip pandas for a multiple column in a data frame

Here is the df:

JavaScript

each column in the dataframe has a lower and an upper limit as mentioned in the below list

eg:

JavaScript

But this returns every element as nan

whereas the expected result is to clip each column based on the upper limit and lower limit mentioned in the list…

Using for loop, I was able to make the necessary change, but it was extremely slower when the size of df is huge

I understand clipping is the faster way to make the changes to df but it doesnt work as expected, I am doing some mistake in it and advice if any other alternative ways of clipping the columns in a faster way?

Advertisement

Answer

From documentation, lower and upper must be float or array-like, not Series.

You could do

JavaScript

but column Type 8 is as string so you’d get an empty column with clip, you can fix with

JavaScript
User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement