python data processing with pandasweb.cse.ohio-state.edu/~shen.94/5544/pandas.pdf · 2020. 9....
TRANSCRIPT
![Page 1: Python Data Processing with Pandasweb.cse.ohio-state.edu/~shen.94/5544/pandas.pdf · 2020. 9. 1. · Pandas • A very powerful package of Python for manipulang tables • Built on](https://reader036.vdocuments.net/reader036/viewer/2022071112/5fe7e858c0070100f65610ac/html5/thumbnails/1.jpg)
PythonDataProcessingwithPandas
CSE5542Introduc:ontoDataVisualiza:on
![Page 2: Python Data Processing with Pandasweb.cse.ohio-state.edu/~shen.94/5544/pandas.pdf · 2020. 9. 1. · Pandas • A very powerful package of Python for manipulang tables • Built on](https://reader036.vdocuments.net/reader036/viewer/2022071112/5fe7e858c0070100f65610ac/html5/thumbnails/2.jpg)
Pandas
• AverypowerfulpackageofPythonformanipula:ngtables
• Builtontopofnumpy,soisefficient
• Saveyoualotofeffortfromwri:nglowerpythoncodeformanipula:ng,extrac:ng,andderivingtablesrelatedinforma:on
• Easyvisualiza:onwithMatplotlib
• Maindatastructures–SeriesandDataFrame
![Page 3: Python Data Processing with Pandasweb.cse.ohio-state.edu/~shen.94/5544/pandas.pdf · 2020. 9. 1. · Pandas • A very powerful package of Python for manipulang tables • Built on](https://reader036.vdocuments.net/reader036/viewer/2022071112/5fe7e858c0070100f65610ac/html5/thumbnails/3.jpg)
• Firstthingfirst
• Series:anindexed1Darray
![Page 4: Python Data Processing with Pandasweb.cse.ohio-state.edu/~shen.94/5544/pandas.pdf · 2020. 9. 1. · Pandas • A very powerful package of Python for manipulang tables • Built on](https://reader036.vdocuments.net/reader036/viewer/2022071112/5fe7e858c0070100f65610ac/html5/thumbnails/4.jpg)
• Explicitindex
• Accessdata
![Page 5: Python Data Processing with Pandasweb.cse.ohio-state.edu/~shen.94/5544/pandas.pdf · 2020. 9. 1. · Pandas • A very powerful package of Python for manipulang tables • Built on](https://reader036.vdocuments.net/reader036/viewer/2022071112/5fe7e858c0070100f65610ac/html5/thumbnails/5.jpg)
• Canworkasadic:onary
• Accessandslicedata
![Page 6: Python Data Processing with Pandasweb.cse.ohio-state.edu/~shen.94/5544/pandas.pdf · 2020. 9. 1. · Pandas • A very powerful package of Python for manipulang tables • Built on](https://reader036.vdocuments.net/reader036/viewer/2022071112/5fe7e858c0070100f65610ac/html5/thumbnails/6.jpg)
DataFrameObject
• Generalizedtwodimensionalarraywithflexiblerowandcolumnindices
![Page 7: Python Data Processing with Pandasweb.cse.ohio-state.edu/~shen.94/5544/pandas.pdf · 2020. 9. 1. · Pandas • A very powerful package of Python for manipulang tables • Built on](https://reader036.vdocuments.net/reader036/viewer/2022071112/5fe7e858c0070100f65610ac/html5/thumbnails/7.jpg)
DataFrameObject
• Generalizedtwodimensionalarraywithflexiblerowandcolumnindices
![Page 8: Python Data Processing with Pandasweb.cse.ohio-state.edu/~shen.94/5544/pandas.pdf · 2020. 9. 1. · Pandas • A very powerful package of Python for manipulang tables • Built on](https://reader036.vdocuments.net/reader036/viewer/2022071112/5fe7e858c0070100f65610ac/html5/thumbnails/8.jpg)
DataFrameObject
• FromPandasSeries
![Page 9: Python Data Processing with Pandasweb.cse.ohio-state.edu/~shen.94/5544/pandas.pdf · 2020. 9. 1. · Pandas • A very powerful package of Python for manipulang tables • Built on](https://reader036.vdocuments.net/reader036/viewer/2022071112/5fe7e858c0070100f65610ac/html5/thumbnails/9.jpg)
DataFrameObject
• FromPandasSeries
![Page 10: Python Data Processing with Pandasweb.cse.ohio-state.edu/~shen.94/5544/pandas.pdf · 2020. 9. 1. · Pandas • A very powerful package of Python for manipulang tables • Built on](https://reader036.vdocuments.net/reader036/viewer/2022071112/5fe7e858c0070100f65610ac/html5/thumbnails/10.jpg)
DataFrameObject
• Anotherexample
![Page 11: Python Data Processing with Pandasweb.cse.ohio-state.edu/~shen.94/5544/pandas.pdf · 2020. 9. 1. · Pandas • A very powerful package of Python for manipulang tables • Built on](https://reader036.vdocuments.net/reader036/viewer/2022071112/5fe7e858c0070100f65610ac/html5/thumbnails/11.jpg)
ViewingData
• ViewthefirstorlastNrows
![Page 12: Python Data Processing with Pandasweb.cse.ohio-state.edu/~shen.94/5544/pandas.pdf · 2020. 9. 1. · Pandas • A very powerful package of Python for manipulang tables • Built on](https://reader036.vdocuments.net/reader036/viewer/2022071112/5fe7e858c0070100f65610ac/html5/thumbnails/12.jpg)
ViewingData
• Displaytheindex,columns,anddata
![Page 13: Python Data Processing with Pandasweb.cse.ohio-state.edu/~shen.94/5544/pandas.pdf · 2020. 9. 1. · Pandas • A very powerful package of Python for manipulang tables • Built on](https://reader036.vdocuments.net/reader036/viewer/2022071112/5fe7e858c0070100f65610ac/html5/thumbnails/13.jpg)
ViewingData
• Quicksta:s:cs(forcolumnsABCDinthiscase)
![Page 14: Python Data Processing with Pandasweb.cse.ohio-state.edu/~shen.94/5544/pandas.pdf · 2020. 9. 1. · Pandas • A very powerful package of Python for manipulang tables • Built on](https://reader036.vdocuments.net/reader036/viewer/2022071112/5fe7e858c0070100f65610ac/html5/thumbnails/14.jpg)
ViewingData
• Sor:ng:sortbytheindex(i.e.,reordercolumnsorrows),notbythedatainthetable
column
![Page 15: Python Data Processing with Pandasweb.cse.ohio-state.edu/~shen.94/5544/pandas.pdf · 2020. 9. 1. · Pandas • A very powerful package of Python for manipulang tables • Built on](https://reader036.vdocuments.net/reader036/viewer/2022071112/5fe7e858c0070100f65610ac/html5/thumbnails/15.jpg)
ViewingData
• Sor:ng:sortbythedatavalues
![Page 16: Python Data Processing with Pandasweb.cse.ohio-state.edu/~shen.94/5544/pandas.pdf · 2020. 9. 1. · Pandas • A very powerful package of Python for manipulang tables • Built on](https://reader036.vdocuments.net/reader036/viewer/2022071112/5fe7e858c0070100f65610ac/html5/thumbnails/16.jpg)
Selec:ngData
• Selec:ngusingalabel
![Page 17: Python Data Processing with Pandasweb.cse.ohio-state.edu/~shen.94/5544/pandas.pdf · 2020. 9. 1. · Pandas • A very powerful package of Python for manipulang tables • Built on](https://reader036.vdocuments.net/reader036/viewer/2022071112/5fe7e858c0070100f65610ac/html5/thumbnails/17.jpg)
Selec:ngData
• Mul:-axis,bylabel
![Page 18: Python Data Processing with Pandasweb.cse.ohio-state.edu/~shen.94/5544/pandas.pdf · 2020. 9. 1. · Pandas • A very powerful package of Python for manipulang tables • Built on](https://reader036.vdocuments.net/reader036/viewer/2022071112/5fe7e858c0070100f65610ac/html5/thumbnails/18.jpg)
Selec:ngData
• Mul:-axis,bylabelSlicing:lastincluded
![Page 19: Python Data Processing with Pandasweb.cse.ohio-state.edu/~shen.94/5544/pandas.pdf · 2020. 9. 1. · Pandas • A very powerful package of Python for manipulang tables • Built on](https://reader036.vdocuments.net/reader036/viewer/2022071112/5fe7e858c0070100f65610ac/html5/thumbnails/19.jpg)
Selec:ngData
• Selectbyposi:on
![Page 20: Python Data Processing with Pandasweb.cse.ohio-state.edu/~shen.94/5544/pandas.pdf · 2020. 9. 1. · Pandas • A very powerful package of Python for manipulang tables • Built on](https://reader036.vdocuments.net/reader036/viewer/2022071112/5fe7e858c0070100f65610ac/html5/thumbnails/20.jpg)
Selec:ngData
• Booleanindexing
![Page 21: Python Data Processing with Pandasweb.cse.ohio-state.edu/~shen.94/5544/pandas.pdf · 2020. 9. 1. · Pandas • A very powerful package of Python for manipulang tables • Built on](https://reader036.vdocuments.net/reader036/viewer/2022071112/5fe7e858c0070100f65610ac/html5/thumbnails/21.jpg)
Selec:ngData
• Booleanindexing
![Page 22: Python Data Processing with Pandasweb.cse.ohio-state.edu/~shen.94/5544/pandas.pdf · 2020. 9. 1. · Pandas • A very powerful package of Python for manipulang tables • Built on](https://reader036.vdocuments.net/reader036/viewer/2022071112/5fe7e858c0070100f65610ac/html5/thumbnails/22.jpg)
SeZngData
• SeZnganewcolumnalignedbyindexes
![Page 23: Python Data Processing with Pandasweb.cse.ohio-state.edu/~shen.94/5544/pandas.pdf · 2020. 9. 1. · Pandas • A very powerful package of Python for manipulang tables • Built on](https://reader036.vdocuments.net/reader036/viewer/2022071112/5fe7e858c0070100f65610ac/html5/thumbnails/23.jpg)
SeZngData
![Page 24: Python Data Processing with Pandasweb.cse.ohio-state.edu/~shen.94/5544/pandas.pdf · 2020. 9. 1. · Pandas • A very powerful package of Python for manipulang tables • Built on](https://reader036.vdocuments.net/reader036/viewer/2022071112/5fe7e858c0070100f65610ac/html5/thumbnails/24.jpg)
Opera:ons
• Descrip:vesta:s:cs– Acrossaxis0(rows),i.e.,columnmean
– Acrossaxis1(column),i.e.,rowmean
![Page 25: Python Data Processing with Pandasweb.cse.ohio-state.edu/~shen.94/5544/pandas.pdf · 2020. 9. 1. · Pandas • A very powerful package of Python for manipulang tables • Built on](https://reader036.vdocuments.net/reader036/viewer/2022071112/5fe7e858c0070100f65610ac/html5/thumbnails/25.jpg)
Opera:ons
• Apply
• Histogram
![Page 26: Python Data Processing with Pandasweb.cse.ohio-state.edu/~shen.94/5544/pandas.pdf · 2020. 9. 1. · Pandas • A very powerful package of Python for manipulang tables • Built on](https://reader036.vdocuments.net/reader036/viewer/2022071112/5fe7e858c0070100f65610ac/html5/thumbnails/26.jpg)
MergeTables
• Join
![Page 27: Python Data Processing with Pandasweb.cse.ohio-state.edu/~shen.94/5544/pandas.pdf · 2020. 9. 1. · Pandas • A very powerful package of Python for manipulang tables • Built on](https://reader036.vdocuments.net/reader036/viewer/2022071112/5fe7e858c0070100f65610ac/html5/thumbnails/27.jpg)
MergeTables
• Append
![Page 28: Python Data Processing with Pandasweb.cse.ohio-state.edu/~shen.94/5544/pandas.pdf · 2020. 9. 1. · Pandas • A very powerful package of Python for manipulang tables • Built on](https://reader036.vdocuments.net/reader036/viewer/2022071112/5fe7e858c0070100f65610ac/html5/thumbnails/28.jpg)
Grouping
![Page 29: Python Data Processing with Pandasweb.cse.ohio-state.edu/~shen.94/5544/pandas.pdf · 2020. 9. 1. · Pandas • A very powerful package of Python for manipulang tables • Built on](https://reader036.vdocuments.net/reader036/viewer/2022071112/5fe7e858c0070100f65610ac/html5/thumbnails/29.jpg)
FileI/O
• CSV
![Page 30: Python Data Processing with Pandasweb.cse.ohio-state.edu/~shen.94/5544/pandas.pdf · 2020. 9. 1. · Pandas • A very powerful package of Python for manipulang tables • Built on](https://reader036.vdocuments.net/reader036/viewer/2022071112/5fe7e858c0070100f65610ac/html5/thumbnails/30.jpg)
FileI/O
• Excel