Python Data Processing with Pandasweb.cse.ohio-state.edu/~shen.94/5544/pandas.pdf · 2020. 9....

30
Python Data Processing with Pandas CSE 5542 Introduc:on to Data Visualiza:on

Transcript of Python Data Processing with Pandasweb.cse.ohio-state.edu/~shen.94/5544/pandas.pdf · 2020. 9....

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

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

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

•  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

•  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

•  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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

FileI/O

•  Excel