### Install pandasql Source: https://github.com/yhat/pandasql/blob/master/README.rst Install the pandasql library using pip. ```bash pip install -U pandasql ``` -------------------------------- ### Joining DataFrames with pandasql Source: https://github.com/yhat/pandasql/blob/master/README.md Illustrates how to perform SQL JOIN operations between pandas DataFrames using pandasql. This example joins 'meat' and 'births' DataFrames on their 'date' column. ```python q = """SELECT m.date, m.beef, b.births FROM meats m INNER JOIN births b ON m.date = b.date;""" joined = pyqldf(q) print joined.head() ``` -------------------------------- ### SQL Aggregation with pandasql Source: https://github.com/yhat/pandasql/blob/master/README.md Shows how to use SQL aggregation functions like SUM and GROUP BY with pandasql. This example calculates the total beef consumption per year from the 'meat' DataFrame. ```python q = "select strftime('%Y', date) as year , SUM(beef) as beef_total FROM meat GROUP BY year;" print pysqldf(q).head() ``` -------------------------------- ### Query DataFrame with PandaSQL Class Source: https://github.com/yhat/pandasql/blob/master/README.rst Demonstrates querying a pandas DataFrame using the PandaSQL class. Load data, create a PandaSQL instance, and execute a SQL query to select the first 10 rows. ```python from pandasql import PandaSQL, load_meat, load_births meat = load_meat() births = load_births() pdsql = PandaSQL() print pdsql("SELECT * FROM meat LIMIT 10;").head() ``` -------------------------------- ### Basic DataFrame Query with pandasql Source: https://github.com/yhat/pandasql/blob/master/README.md Demonstrates how to query a pandas DataFrame using SQL syntax with the sqldf function. A helper function `pysqldf` is defined for convenience. This snippet shows selecting and limiting results from the 'meat' DataFrame. ```python from pandasql import sqldf, load_meat, load_births pysqldf = lambda q: sqldf(q, globals()) meat = load_meat() births = load_births() print pysqldf("SELECT * FROM meat LIMIT 10;").head() ``` -------------------------------- ### Aggregate Data with PandaSQL Source: https://github.com/yhat/pandasql/blob/master/README.rst Calculate the total beef consumption per year by grouping data from the 'meat' DataFrame using a SQL query executed by PandaSQL. ```python q = "select strftime('%Y', date) as year , SUM(beef) as beef_total FROM meat GROUP BY year;" print pdsql(q).head() ``` -------------------------------- ### Join DataFrames with PandaSQL Source: https://github.com/yhat/pandasql/blob/master/README.rst Perform an inner join between two pandas DataFrames ('meats' and 'births') using a SQL query executed by PandaSQL. ```python q = """SELECT m.date, m.beef, b.births FROM meats m INNER JOIN births b ON m.date = b.date;""" joined = pdsql(q) print joined.head() ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.