# 导入pandas库
import pandas as pd
import numpy as np
import pymysql
import matplotlib.pyplot as plt
# 将tweets.csv读取到pandas DataFrame
tweets = pd.read_excel("recharge_data.xlsx")
# 打印DataFrame的前5行
tweets.head()
#连接数据库
#!/usr/bin/python3
import pymysql
# 打开数据库连接
db = pymysql.connect("localhost","testuser","test123","TESTDB" )
# 使用 cursor() 方法创建一个游标对象 cursor
cursor = db.cursor()
# 使用 execute() 方法执行 SQL 查询
cursor.execute("SELECT VERSION()")
# 使用 fetchone() 方法获取单条数据.
data = cursor.fetchone()
print ("Database version : %s " % data)
# 关闭数据库连接
db.close()
# SQL 查询语句
sql = "SELECT * FROM vis_for_gmv_income where date_count='2017-04'"
try:
# 执行SQL语句
cursor.execute(sql)
rows = cursor.fetchall()
# 获取所有记录列表
for row in rows:
print (row)
# 打印结果
except:
print ("Error: unable to fetch data")
【链接clickhouse】
安装
pip install clickhouse-driver
链接数据库
from clickhouse_driver import Client
client = Client(host='192.168.XXX.XXX', database='default', user='root', password='root')
client.execute('SHOW DATABASES')
插入数据
sql = ("insert into table select * from table_name limit 10")
client.execute(sql)