seebe1c / Capstone-Option-1-MuscleHub-A-B-Test

Python project using SQL, Panda, Matplotlib to analyse an A/B test for a gym
0 stars 0 forks source link

Use pandas series apply #1

Open sen1 opened 6 years ago

sen1 commented 6 years ago

https://github.com/seebe1c/Capstone-Option-1-MuscleHub-A-B-Test/blob/54eb409b0b9fc2b245bc63afeb74aeee763629dc/MuscleHub%20Solutions_christa.py#L91-L93

There are two ways to use the apply function. If you have a data frame you have to set the axis=1 argument. However in case of pandas series that argument is redundant since there is only one column. Check there is no axis argument here: https://pandas.pydata.org/pandas-docs/stable/generated/pandas.Series.apply.html

So I would do:

df['ab_test_group'] = df.fitness_test_date.apply(lambda x:
                                                'A' if pd.notnull(x) else 'B')