Skip to content
Advertisement

Pandas ‘count(distinct)’ equivalent

I am using Pandas as a database substitute as I have multiple databases (Oracle, SQL Server, etc.), and I am unable to make a sequence of commands to a SQL equivalent.

I have a table loaded in a DataFrame with some columns:

JavaScript

In SQL, to count the amount of different clients per year would be:

JavaScript

And the result would be

JavaScript

How can I do that in Pandas?

Advertisement

Answer

I believe this is what you want:

JavaScript

Example:

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