Skip to content
Advertisement

How do you identify which IDs have an increasing value over time in another column in a Python dataframe?

Lets say I have a data frame with 3 columns:

JavaScript

ID column contains the ID of a particular person. Value column contains the value of their transaction. Date column contains the date of their transaction.

Is there a way in Python to identify ID 1 as the ID with the increasing value of transactions over time?

I’m looking for some way I can extract ID 1 as my desired ID with increasing value of transactions, filter out ID 2 because it doesn’t have enough transactions to analyze a trend and also filter out ID 3 as it’s trend of transactions is declining over time.

Advertisement

Answer

JavaScript

Output:

JavaScript

Only increasing ID:

JavaScript

Result:

JavaScript

Assuming this won’t happen

JavaScript

If so, then:

JavaScript

Output:

JavaScript

Concat strings:

JavaScript

Intermediate Result:

JavaScript

Check if decrease exist in a row / only “–” exists. Drop them

JavaScript

Result:

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