Using pandas to manipulate MySQL data

Source: Internet
Author: User

Tag: Das name root mysq panda from src add creat

The code is as follows:

#导入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)

Using the LOC function

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]

Using pandas to manipulate MySQL data

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.