Jupyter相关学习笔记

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值