Youtube Videokommentar ist ebenfalls verfügbar.
P-029: Ermitteln Sie den häufigsten Wert des Produktcodes (product_cd) für jeden Geschäftscode (store_cd) für den Datenrahmen für Belegdetails (df_receipt).
Code
df_receipt.groupby('store_cd').product_cd.apply(lambda x: x.mode()).reset_index() \
.set_index(['store_cd','level_1','product_cd'])
store_cd | level_1 | product_cd |
---|---|---|
S12007 | 0 | P060303001 |
S12013 | 0 | P060303001 |
S12014 | 0 | P060303001 |
S12029 | 0 | P060303001 |
S12030 | 0 | P060303001 |
S13001 | 0 | P060303001 |
S13002 | 0 | P060303001 |
S13003 | 0 | P071401001 |
S13004 | 0 | P060303001 |
S13005 | 0 | P040503001 |
S13008 | 0 | P060303001 |
S13009 | 0 | P060303001 |
S13015 | 0 | P071401001 |
S13016 | 0 | P071102001 |
S13017 | 0 | P060101002 |
S13018 | 0 | P071401001 |
S13019 | 0 | P071401001 |
S13020 | 0 | P071401001 |
S13031 | 0 | P060303001 |
S13032 | 0 | P060303001 |
S13035 | 0 | P040503001 |
S13037 | 0 | P060303001 |
S13038 | 0 | P060303001 |
S13039 | 0 | P071401001 |
S13041 | 0 | P071401001 |
S13043 | 0 | P060303001 |
S13044 | 0 | P060303001 |
S13051 | 0 | P050102001 |
1 | P071003001 | |
2 | P080804001 | |
S13052 | 0 | P050101001 |
S14006 | 0 | P060303001 |
S14010 | 0 | P060303001 |
S14011 | 0 | P060101001 |
S14012 | 0 | P060303001 |
S14021 | 0 | P060101001 |
S14022 | 0 | P060303001 |
S14023 | 0 | P071401001 |
S14024 | 0 | P060303001 |
S14025 | 0 | P060303001 |
S14026 | 0 | P071401001 |
S14027 | 0 | P060303001 |
S14028 | 0 | P060303001 |
S14033 | 0 | P071401001 |
S14034 | 0 | P060303001 |
S14036 | 0 | P040503001 |
1 | P060101001 | |
S14040 | 0 | P060303001 |
S14042 | 0 | P050101001 |
S14045 | 0 | P060303001 |
S14046 | 0 | P060303001 |
S14047 | 0 | P060303001 |
S14048 | 0 | P050101001 |
S14049 | 0 | P060303001 |
S14050 | 0 | P060303001 |
-Pandas DataFrame / Serie.
Einzelheiten zum Multi-Index finden Sie unter hier **
Im Falle des bisherigen Problemflusses möchten Sie mit diesem Code antworten, es wird jedoch ein Fehler zurückgegeben. Bitte beachten Sie, dass 'Modus' nicht mit '.agg' berechnet werden kann.
Code
df_receipt.groupby('store_cd').agg({'product_cd':'mode'}).reset_index()
Recommended Posts