+ 1

using pandas

using pandas import pandas as pd import numpy as np orders = pd.read_table('http://bit.ly/chiporders') orders.item_name.nunique() orders.head() orders.iloc[pd.Index(orders['order_id']).get_indexer(['1','1','2'])] Find five most commonly ordered (don't take quantity into account) items along with a number of orders; Can you please tell how to fix?

26th Oct 2021, 7:39 AM
Zhenis Otarbay
Zhenis Otarbay - avatar
1 Respuesta
+ 1
df_top_freq = orders.groupby(['order_id', 'item_name'])['order_id'].agg( {"code_count": len}).sort_values( "code_count", ascending=False).head(n).reset_index()
26th Oct 2021, 7:43 AM
Zhenis Otarbay
Zhenis Otarbay - avatar