Programming Principles in Python (CSCI 503/490)

Programming Principles in Python (CSCI 503/490)

Visualization

Dr. David Koop

D. Koop, CSCI 503/490, Fall 2021

Derived Data

? Create new columns from existing columns

- r["PctFail"] = r['Fail'] / r['Total']

? Note that operations are computed in a vectorized manner ? Similarities to functional paradigm (map/ lter):

- specify the operation once - no loops - interpreted as an operation on the entire column

D. Koop, CSCI 503/490, Fall 2021

2

if

producing a new value. Finally, the results of all those function applications are combined into a result object. The form of the resulting object will usually depend on what's

Aggregbeaingtidoonne :toSthepdlaitta-. SAeepFipgulrye 9--C1 foor ma mbockinupeof a simple group aggregation.

D. Koop, CSCI 5F0i3g/u4r9e0,9F-1a.llI2ll0u2s1tration of a group aggregation

[W. McKinney, Python for Data Analysis]

3

Split-Apply-Combine

? df.groupby('Island')[['Culmen Length (mm)', 'Culmen Depth (mm)']].mean()

? df.groupby('Island').agg({'Culmen Length (mm)': 'mean', 'Culmen Depth (mm)': 'mean'})

? df.groupby('Island').agg( cul_length=('Culmen Length (mm)', 'mean'), cul_depth=('Culmen Depth (mm)', 'mean'))

D. Koop, CSCI 503/490, Fall 2021

4

Melt

? Want to keep each observation separate (tidy), aka pivot_longer

df.melt(id_vars=["location", "Temperature"], var_name="Date", value_name="Value")

D. Koop, CSCI 503/490, Fall 2021

[AB Abhi]

5

................
................

In order to avoid copyright disputes, this page is only a partial summary.

Google Online Preview   Download