- Python Data Analysis(Second Edition)
- Armando Fandango
- 158字
- 2021-07-09 19:04:08
Pivot tables
A pivot table, as used in Excel, summarizes data. So far, the data in CSV files that we have seen in this chapter has been in flat files. The pivot table aggregates data from a flat file for certain columns and rows. The aggregating operation can be sum, mean, standard deviations, and so on. We will reuse the data-generating code from ch-03.ipynb
. The Pandas API has a top-level pivot_table()
function and a corresponding DataFrame method. With the aggfunc
parameter, we can specify the aggregation function to, say, use the NumPy sum()
function. The cols
parameter tells Pandas the column to be aggregated. Create a pivot table on the Food
column as follows:
print(pd.pivot_table(df, cols=['Food'], aggfunc=np.sum))
The pivot table we get contains totals for each food item:
Food chocolate icecream soup Number 8.000000 15.000000 19.00000 Price 5.986585 10.440071 13.83338 [2 rows x 3 columns]
The preceding code can be found in ch-03.ipynb
in this book's code bundle.
- WildFly:New Features
- Hadoop+Spark大數據分析實戰
- Learn Scala Programming
- Building Cross-Platform Desktop Applications with Electron
- 深度強化學習算法與實踐:基于PyTorch的實現
- INSTANT Django 1.5 Application Development Starter
- Spring核心技術和案例實戰
- Visual Basic程序設計實驗指導(第二版)
- AutoCAD基礎教程
- Getting Started with JUCE
- JavaScript Unit Testing
- Flink原理深入與編程實戰:Scala+Java(微課視頻版)
- Mastering Python for Data Science
- 新手學Visual C
- 數據庫技術及應用(Access)(第2版)