Create new column by selecting dataframe subset based on current row value and sum another column

Lets say we have a sample dataframe that looks like this # Create a sample dataframe df = pd.DataFrame({‘num_posts’: [4, 6, 3, 9, 1, 14, 2, 5, 7, 2,12], ‘date’ : [‘2020-03-01’, ‘2020-01-02’, ‘2020-01-03’, ‘2020-01-04’, ‘2019-01-05’, ‘2019-01-06’, ‘2020-01-07’, ‘2020-01-08’, ‘2020-01-09’, ‘2020-01-10′,’2020-01-11’]}) cols=[‘num_posts’] Now i need to create features such as sum(num_posts) for last week of… Read More Create new column by selecting dataframe subset based on current row value and sum another column

How to understand this lambda with 3 .replace() line of code

df[‘Current Ver’] = df[‘Current Ver’].astype(str).apply(lambda x : x.replace(‘.’, ‘,’,1).replace(‘.’, ”).replace(‘,’, ‘.’,1)).astype(float) Slowly learning lambda command, my understanding of this line of code is: Change dataframe type to str Apply lambda with one perimeter x Replace all the string format . to , , (I don’t understand what does 1 stands for, have done research prior… Read More How to understand this lambda with 3 .replace() line of code