Read a sql table 'where in' as a Dataframe



    Javier Pacheco

    The code reads a SQL statement from the file input. It uses the string concatenation operator (+) to define a list of column identifiers. It then passes that list to the read_sql() function, which will select all the columns from the table named table where the column identifier in the list matches the given identifier.

    import pandas as pd
    df = pd.read_sql(
      "SELECT columns "+
      "FROM table "
      "WHERE column IN ({})".format(', '.join([str(id) for id in list]))
    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.