In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-09-15 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/02 Report--
This article to share with you is about how to implement a pivot table in Python, Xiaobian feel quite practical, so share to everyone to learn, I hope you can read this article after some gains, not much to say, follow Xiaobian to see it.
1. Preview data sources
#Preview Data Source df
2. Calculate the average number of sales per year
#Calculate the average number of sales per year pd.pivot_table(df, index = "Year", values = "Number of Sales" )
3. Calculate total sales for each year
#Calculate total sales per year pd.pivot_table(df, index = "year", values = "sales" ,aggfunc = "sum")
4. Calculate the total sales volume of various commodities in each province
#Calculate the total sales volume of various commodities in each province pd.pivot_table(df, index = "province", columns = "commodity", values = "sales volume" ,aggfunc = "sum")
5. Calculate the total sales quantity of various commodities in each province, and force the error value to 0
#Calculate the total sales quantity of various commodities in each province and force the error value to be 0pd.pivot_table(df, index = "province", columns = "commodity", values = "sales quantity" ,aggfunc = "sum").fillna("0")
6. Calculate the total sales quantity of various commodities in each province, and force the error value to be displayed as 0. Add total rows and columns
#Calculate the total sales quantity of various commodities in each province and force the error value to 0. Add the total row and column pd.pivot_table(df, index = "province", columns = "commodity", values = "sales quantity" ,aggfunc = "sum",margins = True).fillna("0")
7. #Calculate the total sales quantity of various commodities in each province, force the error value to display 0. Add total rows and columns, and rename total rows
#Calculate the total sales quantity of various commodities in each province and force the error value to 0. Add the total row and column and rename the total row pd.pivot_table(df, index = "province", columns = "commodity", values = "sales quantity" ,aggfunc = "sum",margins = True,margins_name = "total").fillna("0")
The above is how to implement a pivot table in Python, Xiaobian believes that some knowledge points may be seen or used in our daily work. I hope you can learn more from this article. For more details, please follow the industry information channel.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
The market share of Chrome browser on the desktop has exceeded 70%, and users are complaining about
The world's first 2nm mobile chip: Samsung Exynos 2600 is ready for mass production.According to a r
A US federal judge has ruled that Google can keep its Chrome browser, but it will be prohibited from
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
About us Contact us Product review car news thenatureplanet
More Form oMedia: AutoTimes. Bestcoffee. SL News. Jarebook. Coffee Hunters. Sundaily. Modezone. NNB. Coffee. Game News. FrontStreet. GGAMEN
© 2024 shulou.com SLNews company. All rights reserved.