Data Analytics: Merge, rename, Pivot Table




    The code first renames the columns to match the columns in the with_df. Next, it checks to see if the value in the title column matches the rating_merged_test column. If it does, the code creates a new variable called gen_df2 and assigns it the value from gen_df. Next, it sorts gen_df values by isbn.

    result_df = start_df.merge(with_df, on= "title")
    # rename columns
    rating_merged_test = rating_merged_test.rename(columns={'Book-Title':'title'})
    # Check if value is in column
    gen_df2 = gen_df[gen_df["title"].isin(rating_merged["Book-Title"])]
    # Sort values
    isbns = gen_df.sort_values(by="isbn", ascending=False)
    # Piv- Table
    piv_table= rating_merged.pivot_table(columns="User-ID",index="ISBN", values="Book-Rating")
    Codiga Logo
    Codiga Hub
    • Rulesets
    • Playground
    • Snippets
    • Cookbooks
    soc-2 icon

    We are SOC-2 Compliance Certified

    G2 high performer medal

    Codiga – All rights reserved 2022.