In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-18 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: 272
*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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.