Python 熊猫:如何从excel在sqlite数据库中存储列表
我有一个excel表格,如下所示:Python 熊猫:如何从excel在sqlite数据库中存储列表,python,excel,pandas,list,sqlite,Python,Excel,Pandas,List,Sqlite,我有一个excel表格,如下所示: A | B | C | D | E 1 |11|2 | 3 |4|5|6 | 7 aa|ee | s |34|7 | hi A | B | C | D | E 1 |[['11'],['2']] | [['3']] |[['4'],['5'],['6']] | 7 aa|[['ee']] | [['s']] |[['34'],
A | B | C | D | E
1 |11|2 | 3 |4|5|6 | 7
aa|ee | s |34|7 | hi
A | B | C | D | E
1 |[['11'],['2']] | [['3']] |[['4'],['5'],['6']] | 7
aa|[['ee']] | [['s']] |[['34'],['7']] | hi
我需要在sqlite中插入一个表,如下所示:
A | B | C | D | E
1 |11|2 | 3 |4|5|6 | 7
aa|ee | s |34|7 | hi
A | B | C | D | E
1 |[['11'],['2']] | [['3']] |[['4'],['5'],['6']] | 7
aa|[['ee']] | [['s']] |[['34'],['7']] | hi
只有列B C D是列表,值可以用管道分隔
我已经编写了一个函数,但它似乎没有给出正确的输出:
def on_pushButton_import_pressed(self):
'''import eamena excel file into HFF System'''
conn = Connection()
conn_str = conn.conn_str()
try:
EXCEL_FILE_NAME = self.lineEdit_path_excel.text()
wb = pd.read_excel(EXCEL_FILE_NAME,skiprows=2)
wb.to_sql('eamena_table',conn_str, if_exists='append',index=False)
except Exception as e:
QMessageBox.warning(self, "Error", str(e),QMessageBox.Ok)
如何修复它?为数组使用第二个表,每个数组中的每个值的格式为
OriginalRowID | Value
。嗨@forgetso我不太明白你的意思,但我正在寻找pandas中的“at”和“loc”方法在列表中转换每个单元格我的意思是使用SQL中的关系表模型来存储关系数据。如果您想将其保存在pandas中,只需使用explode
将列表项放入单独的行中即可。