SELECT occupation, COUNT(*)
FROM customer
GROUP BY occupation;
EVALUATE
SUMMARIZE(
customer,
customer[occupation],
"Count", COUNTROWS(customer)
)
import pandas as pd
# Sample DataFrame
data = {
'occupation': ['Engineer', 'Doctor', 'Engineer', 'Artist', 'Doctor']
}
df = pd.DataFrame(data)
# Group by occupation and count the occurrences
df_result = df.groupby('occupation').size().reset_index(name='Count')
# Convert to list of lists
result = df_result.values.tolist()
print(result)
| Artist | 1 |
| Doctor | 2 |
| Engineer | 2 |
SUMMARIZE: Groups the customer table by the occupation column. COUNTROWS(customer): Counts the number of rows for each occupation.
Leave a Comment