02119 Most Lucrative Products


# Import your libraries
import pandas as pd
# Start writing code
online_orders.head()
online_orders = online_orders[online_orders['date_sold'].between('2022-01-01','2022-06-30')]
online_orders['total_revenue'] = online_orders['cost_in_dollars'] * online_orders['units_sold']
online_orders.groupby('product_id')['total_revenue'].sum().reset_index(name='revenue').sort_values('revenue',ascending=False).head(5)
๐ฅ product ๋ณ revenue ์ต๋๊ฐ 5๊ฐ ์ ๋ณด ์ถ๋ ฅ.
(1) betweenํ ๋ ์ผ์๊น์ง ์ ํํ๊ฒ filtering ํ์
(2) reset_index()์์ name ์ ํํ ๊ธฐ์ ํ๊ณ , ๊ทธ name์ ๋ง๊ฒ sort_values()์์ ๊ธฐ์
'Data Science Fundamentals > Pandas&Numpy and Questions' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
๐ฅฐ StrataScratch PythonPandas Medium I - 18 Solved (0) | 2025.03.09 |
---|---|
map & applymap & apply(for dataframe & Series) (1) | 2024.06.02 |
dataframe ๊พธ๋ฏธ๊ธฐ (1) | 2023.01.22 |
Numpy fundamentals 2/2 (0) | 2023.01.16 |
pandas Tricks (Kevin by DataSchool) ์๋ฃ! COMPILATION (0) | 2022.04.18 |
๋๊ธ