我想合并数据。以下是我的 MySQL 表。我想使用 Python 遍历两个列表的列表(一个带有 dupe = 'x' 和另一个带有 null dupes)。
这是样本数据。实际数据非常庞大。
例如 :
a b c d e f key dupe
--------------------
1 d c f k l 1 x
2 g h j 1
3 i h u u 2
4 u r t 2 x
从上面的示例表中,所需的输出是:
a b c d e f key dupe
--------------------
2 g c h k j 1
3 i r h u u 2
到目前为止我所拥有的:
import string, os, sys
import MySQLdb
from EncryptedFile import EncryptedFile
enc = EncryptedFile( os.getenv("HOME") + '/.py-encrypted-file')
user = enc.getValue("user")
pw = enc.getValue("pw")
db = MySQLdb.connect(host="127.0.0.1", user=user, passwd=pw,db=user)
cursor = db.cursor()
cursor2 = db.cursor()
cursor.execute("select * from delThisTable where dupe is null")
cursor2.execute("select * from delThisTable where dupe is not null")
result = cursor.fetchall()
result2 = cursor2.fetchall()
for each record
for each field
perform the comparison and perform the necessary updates
### How do I compare the record with same key value and update the original row null field value with the non-null value from the duplicate? Please fill this void...
cursor.close()
cursor2.close()
db.close()
多谢你们!