当前位置:网站首页>pandas的to_sql函数使用
pandas的to_sql函数使用
2022-07-27 16:12:00 【zkkkkkkkkkkkkk】
目录
2.使用pandas的to_sql将data数据写入到mysql
1.引入相关库函数
import pandas as pd
import pymysql
2.使用pandas的to_sql将data数据写入到mysql
'''
to_sql()内置参数:
name : 写入到mysql的表名
con :连接地址
if_exists : 追加方式 (可选参数{‘fail’, ‘replace’, ‘append’},默认fail)
index : 是否将data的index和数据一块写入到mysql (可选参数{‘True’,‘False’},默认为True)
'''
'''
account : 主机名
password: 密码
port : 端口号
dbName : 库名
'''
# 获取engine
url = f'{account}:{password}@{host}:{port}/{dbName}?charset=utf8'
con = 'mysql+pymysql://' + url
# data为pandas的dataframe数据对象
data.to_sql(name='sql_demo', con=con, if_exists='append', index=False)
3.查看mysql是否写入成功
根据配置文件信息,使用sql工具连接mysql,点击对应的库下面查找我们写入的表就可以了。
边栏推荐
- Linked list storage structure of dynamic linked list 2 stack (linkedstack Implementation)
- An analysis of CPU explosion of a smart logistics WCS system in.Net
- Disassembly of Xiaomi cc9 Pro: the cost of rear five shots is several times that of Xiaolong 855!
- [MIT 6.S081] Lab 4: traps
- 2021.8.1 Notes database design
- 深度学习-论文阅读:动作结构性图卷积网络AS-GCN
- 2021.7.19 notes DML
- Uniapp has no effect on the page selector on the app side
- 2021.8.1笔记 数据库设计
- [mit 6.s081] LEC 3: OS organization and system calls notes
猜你喜欢

Binary tree concept
![[mit 6.s081] LEC 10: multiprocessors and locking notes](/img/62/ca6362830321feaf450865132cdea9.png)
[mit 6.s081] LEC 10: multiprocessors and locking notes
![[MIT 6.S081] Lab 9: file system](/img/f5/ea30b1fe5b6d73c86f2509c690ca20.png)
[MIT 6.S081] Lab 9: file system
![[MIT 6.S081] Lab 4: traps](/img/8b/ca4819f8b1cfc6233745a124790674.png)
[MIT 6.S081] Lab 4: traps

Nowcoder (5 choices)

2021.7.12 internal and external connection of notes

2021.8.6 notes jsoup
![[MIT 6.S081] Lab 10: mmap](/img/5d/a59a6f723518553b9232bc09991075.png)
[MIT 6.S081] Lab 10: mmap

Publish your own NPM component library

深度学习:GAN优化方法-DCGAN案例
随机推荐
Hackers use lasers to attack, and voice assistants can be activated from a distance of 100 meters
搭建一个简单的知识问答系统
Solve the problem that reids cannot be accessed by other IPS
2021.7.18笔记 mysql数据类型
JDBC学习 Day1:JDBC
2021.7.19 notes DML
MySQL学习 Day1 DDL、DML、DQL基础查询
2021.8.9笔记 request
[MIT 6.S081] Lab 4: traps
Read only mode of buffer
@Considerations for query of convert annotation in JPA
Huawei mate30 Pro 5g disassembly: self developed chips account for more than half, and American chips still exist!
2021.8.1笔记 数据库设计
深度识别:论文阅读_2S-AGCN CVPR2019(基于骨架的动作识别的两流自适应图卷积网络)
Deep learning: GCN case
[MIT 6.S081] Lab 6: Copy-on-Write Fork for xv6
Jrs-303 usage
[MIT 6.S081] Lab 11: networking
[MIT 6.S081] Lec 8: Page faults 笔记
2021.7.22 note constraints