'Number of rows for the subset of the dataframe

My dataframe A_df loads the dataset that contains information on a number of categories regarding traffic (cnt). I must print the number of rows for the subset of the dataframe for which traffic values are higher than 10,000 (ideally, you should format the print to put the thousands comma separator--as in 23,400 instead of 23400).

My code below is not showing me the correct output.

rate = a_df.loc[a_df['cnt'] > 10000]
print(rate)


Solution 1:[1]

To get the number of entries in your dataframe subset, just use:

n_entries = len(rate.index())
print(n_entries)

Regarding printing with the comma separator: it's just a matter of formatting. You could use something like:

print(f'{n_entries//1000},{n_entries-n_entries//1000*1000}' )

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 g__c