代码如下:
#导入
import pymysql
import pandas as pd
from sqlalchemy import create_engine
#连接mysql
engine = create_engine(‘mysql+pymysql://root:@localhost:3306/lg‘)
#查询
sql = ‘‘‘
select LGL_LSKU,LGL_NAME_LOCAL,LGL_RAW_ADDRESS from kfc limit 5;
‘‘‘
df = pd.read_sql_query(sql,engine)
print(df)
使用loc函数
sql_1 = ‘‘‘
select LGL_LSKU,LGL_NAME_LOCAL,LGL_RAW_ADDRESS,LGL_EPISODE,
LGL_EPISODE_DATES,LGL_POI_NOTES,LGL_LSKU_HERIT from kfc;
‘‘‘
df_1 = pd.read_sql_query(sql_1,engine)
df_1.loc[3:6] #使用loc函数查看[3:6]的数据
two_five_ten = [2,5,10]
df_1.loc[two_five_ten]
原文地址:https://www.cnblogs.com/hankleo/p/9575240.html
时间: 2024-10-07 09:29:52