Skip to content
Advertisement

Groupby several columns, summing them up based on the presence of a sub-string

Context: I’m trying to sum all values based in a list only if they start with or contain a string

So with a config file like this:

JavaScript

And a dataframe like this:

JavaScript

How can I group by if they all start by a given substring present on the granularity_suffix_list?

Desired output:

JavaScript

Attempts: I was trying this:

JavaScript

But It doesn’t work. Instead, the function returns a list like ['A_2','A','A_3','A',B_4','B'...]

Thank you

Advertisement

Answer

Okay finally managed to solve what I wanted

Posting the solution if anyone finds it relevant

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