回答此问题可获得 20 贡献值,回答如果被采纳可获得 50 分。
<p>我有下面的数据框</p>
<pre><code>df = pd.DataFrame({'vin': ['test'], 'modelId':['5641'], 'year': ['2021'] })
</code></pre>
<p>我正在尝试使用下面的函数从中创建SQL插入脚本</p>
<pre><code>import pandas as pd
def createSqlInsertStatement():
global sql_texts,row
sql_texts = []
for index, row in df.iterrows():
sql_texts.append('INSERT INTO '+ ' registry'+' (source, create_time, geo_group_id, status, make, vin, modelId, year)'
+ ' VALUES "MANUAL_LOAD", sysdate, 42, 0, "MITSUBISHI", '+ ',' + str(tuple(row.values))) +';'
return sql_texts
</code></pre>
<p>但我一直得到:</p>
<pre><code>TypeError Traceback (most recent call last)
c:\Users\Desktop\testsql.py in <module>
----> 1 createSqlInsertStatement()
c:\Users\Desktop\testsql.py in createSqlInsertStatement()
9 sql_texts = []
10 for index, row in df.iterrows():
---> 11 sql_texts.append('INSERT INTO '+ ' registry'+' (source, create_time, geo_group_id, status, make, vin, modelId, year)'
12 + ' VALUES "MANUAL_LOAD", sysdate, 42, 0, "MITSUBISHI", '+ ',' + str(tuple(row.values))) +';'
13 return sql_texts
TypeError: unsupported operand type(s) for +: 'NoneType' and 'str'
</code></pre>
<p>我需要</p>
<pre><code>INSERT INTO registry (source, create_time, geo_group_id, status, make, vin, modelId, year) VALUES ('MANUAL_LOAD', sysdate, 42, 0, 'MITSUBISHI', '5641', '2021');
</code></pre>
<p>我快要发疯了,正在寻找一种我找不到的“无”类型,还是我看错了</p>