Loading tutorials
[] and loc, and read a groupby aggregation. It also assumes you know the wide and long layouts from the previous chapter. Here you will use DataFrame.melt to convert wide data to long data. You will also learn what it does t5 min read[], and read the output of DataFrame.melt in its simplest form. The earlier chapter showed melt turning columns into rows. Here you will control which columns stay fixed, which are stacked, and what the output columns are call6 min readDataFrame.pivot reshapes a long table into a wide one. It takes the unique values of one column and makes them the row labels. It takes the unique values of another column and makes them the column labels. It then fills each cell from a third column. This chapter covers how that works, the options5 min readmelt turn columns into rows and pivot turn rows into columns. Here you will chain the two calls, see what each round trip changes, and learn how to check that you got your original table back.5 min read[] and loc, and use groupby with aggregations such as sum and mean. It also assumes you have seen DataFrame.pivot turn long data into wide data. Here you will learn why pivot raises an error on some inputs, how to find7 min readpivot fails when two rows share the same index and column pair. pivot_table handles that case. It groups the rows, applies an aggregation function to each group, and lays the results out as a grid.5 min readpivot_table with an aggfunc, as in the previous chapter. It covers two things that follow from that. First, wide tables often contain empty cells, and you need to decide what they mean. Second, you often want totals added, and you need to know how those total5 min read[] and loc, and call pivot_table with an aggfunc. It covers what a column MultiIndex is, which calls produce one, and how to select from it. The next chapter covers flattening it into plain names.4 min readpivot_table and know what a MultiIndex is. The previous chapter covered how to read MultiIndex columns. Here you learn how to turn a pivot result back into an ordinary table. That means one string name per column and the row labels back as a regular column.5 min readmelt and pivot work on ordinary columns. stack and unstack work on index levels instead. They move a level between the row index and the column labels, and they are the tools underneath many groupby results and pivot_table outputs.5 min readmelt (including id_vars, var_name and value_name), basic regular expressions, and how to read a MultiIndex on a DataFrame. Spreadsheets and survey exports often hold several measurements per row, with column names such as score_math, score_art, `hours_math5 min readpivot, pivot_table, and flattening column labels. You should also be comfortable with groupby and size. Here you will learn how pd.crosstab builds frequency tables, when it beats pivot_table, and how to turn its output back into 5 min read