代码如下:
#导入import pymysqlimport pandas as pdfrom sqlalchemy import create_engine
#连接mysqlengine = 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