Skip to content
Advertisement

Tag: apply

Pandas apply() with axis=0 unexpected behaviour

I’m using the .apply() method in pandas. I get the same results when using axis=0 and axis=1. When using axis=0 I’d expect a series with four elements (indexed A, B, C, D) as a result. Can anyone tell me why the axis argument doesn’t work in this case? I’m adding a reproducible example below. NOTE: I know that this is

How to vectorize groupby and apply in pandas?

I’m trying to calculate (x-x.mean()) / (x.std +0.01) on several columns of a dataframe based on groups. My original dataframe is very large. Although I’ve splitted the original file into several chunks and I’m using multiprocessing to run the script on each chunk of the file, but still every chunk of the dataframe is very large and this process never

pandas, apply with args which are dataframe row entries

I have a pandas dataframe ‘df’ with two columns ‘A’ and ‘B’, I have a function with two arguments and I would like to apply it row-by-row to df using the ‘apply’ function but I get the error whats happening here, it seems it takes df[‘A’] as the whole series! not just the row entry from that series as required.

Python pandas calculate rolling stock beta using rolling apply to groupby object in vectorized fashion

I have a large data frame, df, containing 4 columns: etc. I am attempting to calculate a common financial measure, known as beta, using a function, that takes two of the columns, ret_1m, the monthly stock_return, and ret_1m_mkt, the market 1 month return for the same period (period_id). I want to apply a function (calc_beta) to calculate the 12-month result

Python pandas apply function if a column value is not NULL

I have a dataframe (in Python 2.7, pandas 0.15.0): I want to apply a simple function for rows that does not contain NULL values in a specific column. My function is as simple as possible: And my apply code is the following: It works perfectly. If I want to check column ‘B’ for NULL values the pd.notnull() works perfectly as

Advertisement