How to solve the problem of inventory rate of goods by Python
This article introduces the relevant knowledge of "Python how to solve the problem of commodity distribution rate". In the operation process of actual cases, many people will encounter such difficulties. Next, let Xiaobian lead you to learn how to deal with these situations! I hope you can read carefully and learn something!
Available data are as follows:
Sales for each category (cls) for each store (shopid_branch)
Count the distribution rate of each category, i.e. the number of stores selling each category/the total number of stores
Find the total number of stores per year:
shopid_branch_count_year =b_brandsale.groupby(['year']).shopid_branch.nunique().reset_index()\.rename(columns={'shopid_branch':' total stores per year'})#.pivot('year','shopid_branch')
Find the number of stores selling each type of product
shopid_branch_count_year_cls = b_brandsale.groupby(['year','cls']).\ shopid_branch.nunique().reset_index().pivot('year','cls','shopid_branch').reset_index()
Merge the two results together
Find the proportion
for each in ['others ',' milk powder','services',' cotton','toys',' supply','paper',' nutrition','lathe',' complementary food']: #print(each) new_col = each + 'rate' puhuolv[new_col]= puhuolv[each]/puhuolv['total stores per year']
"Python how to solve the problem of commodity distribution rate" content is introduced here, thank you for reading. If you want to know more about industry-related knowledge, you can pay attention to the website. Xiaobian will output more high-quality practical articles for everyone!