【发布时间】:2019-03-30 23:31:29
【问题描述】:
我在 mysql 数据库中存储数据时遇到问题。具有列表df = [['Euro', 0.877641, '2018-10-24'], ['British Pound', 0.7752180000000001, '2018-10-24'], ['Indian Rupee', 73.21869000000001, '2018-10-24'], ['Australian Dollar', 1.4135360000000001, '2018-10-24'], ['Canadian Dollar', 1.299316, '2018-10-24']] 列表的变量希望将其存储在最后更新日期的货币名称、日期、值列中。那么我如何在代码中编写该逻辑(我是使用 sql 的 max()、min() 方法。)
试过了:
import pandas as pd
import pymysql
import MySQLdb
sqlconn = pymysql.connect(host='ip', port=port, user='username',
passwd='pass', db='dbname', autocommit=True)
# Create a cursor object
if (sqlconn == None):
print("conn not found")
else:
print("conn is found")
cursor.execute("INSERT INTO TestCurrencyHistory (currency, date, value) VALUES (%s, %s, %s)") % (
elements
)
element = cursor.fetchall()
cursor.close()
sqlconn.close()
Offcource this is not working. So please help ..
提前谢谢..(如果有任何 python/pandas 逻辑来选择最大和最小日期,请不要告诉我)
【问题讨论】:
-
你好。您能否详细说明您需要输入/输出数据的问题?