使用pandasql对数据运用sql语言

模仿pandasql:让 python 运行 SQL

#去cmd pip install pandasql
from pandasql import sqldf
from pandasql import load_meat, load_births

meat = load_meat()
births = load_births()
#print (meat.head())
#print (births.head())

import matplotlib.pyplot as plt 
from pandas import *
import pandas as pd 

pysqldf = lambda q: sqldf(q,globals())

q="""
SELECT 
    m.date,
    m.beef,
    b.births
FROM 
    meat m
LEFT JOIN
    births b
        ON m.date = b.date
WHERE
    m.date>'1974-12-31';
"""
print(pysqldf(q))

你可能感兴趣的:(python)