pivot table pd examples

Example 1: pivot table pandas

df.pivot_table(['int_age'],index = [df.iloc[:,meet_friends], df.iloc[:,friendsgiving]])

Example 2: pivot table pandas

# Tips is the Dataframe:
# Suppose we want to compute a table of group means, we can
# use the Pivot_Table Method:

# The Pivot Table automatically computes the mean

tips.pivot_table(index=['day', 'smoker'])

# The index represents the column names that you want to form groups

Example 3: pivot table

SELECT *        -- Total invoices per gender
FROM (
    SELECT invoice, gender
    FROM sales
) d
PIVOT (
    sum(invoice)
    FOR gender IN ('F' AS "Women", 'M' AS "Men")
);
-- Table Sales:
CREATE TABLE sales (
    gender VARCHAR2(1 BYTE),		-- 'F' or 'M'
    invoice NUMBER
);

Example 4: pivot table pandas

df.pivot_table(index = [df.iloc[:,meet_friends], df.iloc[:,friendsgiving]])