为了账号安全,请及时绑定邮箱和手机立即绑定

导入Excel到MySQL使用Python和转换datestamp

导入Excel到MySQL使用Python和转换datestamp

哆啦的时光机 2021-05-03 08:53:51
我需要Excel中的数据-这样的int类型的date(20180301)和time(121220)。我想将excel导入mysql,使用python将datetamp(%t-%m-%d%H:%M:%S)转换为一个库仑。import xlrdimport pymysqlimport timeimport datetime#open the workbook and define rhe worksheetbook  = xlrd.open_workbook("d:/waiting2.xlsx")sheet = book.sheet_by_index(0)ts = time.time()timestamp = datetime.datetime.formtimestamp(ts).strftime('%t-%m-%d %H:%M:%S')#sheet = book.sheet_by_index(0)#establish a mysql connectiondatabase = pymysql.connect(host="localhost", user='root', password='1234',db='test')#get the cursor, which is used to traverse the database, line by linecursor = database.cursor()try:    cursor.execute("""INSERT into test(date+time) values($s)""", (timestamp))    database.commit()except:    database.rollback()database.close()AttributeError:类型对象“ datetime.datetime”没有属性“ formtimestamp”
查看完整描述

1 回答

  • 1 回答
  • 0 关注
  • 196 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号