Lecture 14
Lecture 14
Suppose we want to
standardize these scores
within each year. Group the data according to the output
of the key function, apply the given
transformation within each group, then
un-group the data.
We’ll learn about these when we discuss SQL later in the semester
So we won’t discuss them here
If you are already familiar with SQL, you might like to read this:
https://pandas.pydata.org/pandas-docs/stable/comparison_with_sql.html
Data in this format is usually called stacked. It
Pivoting and Stacking is common to store data in this form in a file, but
once it’s read into a table, it often makes more
sense to create columns for A, B and C. That is,
we want to unstack this DataFrame.
Pivoting and Stacking The pivot method takes care of unstacking
DataFrames. We supply indices for the new
DataFrame, and tell it to turn the variable
column in the old DataFrame into a set of
column names in the unstacked one.
https://en.wikipedia.org/wiki/Pivot_table
Pivoting and Stacking
Recommended:
Merge, join and concatenation:
https://pandas.pydata.org/pandas-docs/stable/merging.html
Time series functionality:
https://pandas.pydata.org/pandas-docs/stable/timeseries.html