将数据框导出到Oracle:TypeError [英] Exporting Dataframe to Oracle: TypeError
问题描述
我多次无法将以下数据框导出到我的Oracle表:
I am repeatedly failing to export the following Dataframe to my Oracle table:
final df is: S USTAINABLE H ARVEST S ECTOR| QUOTA LISTING JUN 11 2013 Unnamed: 1 \
2 6/4/13 130196
3 5/28/13 130158
4 6/4/13 130210
5 5/14/13 130079
6 6/4/13 130187
7 6/4/13 130208
8 6/11/13 130249
9 6/4/13 130204
10 5/28/13 130148
11 5/28/13 130149
12 5/28/13 130157
13 5/21/13 130105
14 5/21/13 130106
15 6/4/13 130205
16 6/11/13 130250
17 6/4/13 130206
18 6/11/13 130248
19 QUOTA TO BUY 0
20 DATE TRADE ID
21 6/11/13 130239
22 5/14/13 130074
23 3/26/13 130006
24 5/14/13 130075
25 5/7/13 130023
26 5/14/13 130039
27 1 0
Unnamed: 2 Unnamed: 3 Unnamed: 4 email_year email_month \
2 COD GBW 10000 0.6 2013 6
3 COD GBW 300 0.6 2013 6
4 HADDOCK GBE UP TO 30,000 OFFERS 2013 6
5 PLAICE 1000 0.45 2013 6
6 WHITE HAKE UP TO 25,000 0.5 2013 6
7 WHITE HAKE 4000 0.5 2013 6
8 WINTER GB 3300 0.25 2013 6
9 WINTER GB 10000 0.48 2013 6
10 WINTER GB 1U0P 0T,0O00 0.25 2013 6
11 WINTER GB UP TO 10,000 0.4 2013 6
12 WINTER GB 1400 0.25 2013 6
13 WINTER GB 10000 0.5 2013 6
14 WINTER GB 10000 0.5 2013 6
15 WINTER GOM 1000 0.38 2013 6
16 WINTER SNE 6500 0.4 2013 6
17 WINTER SNE 3000 0.63 2013 6
18 YELLOWTAIL GOM 2000 1.25 2013 6
19 0 0 0 2013 6
20 DESIRED STOCK AMOUNT BUY PRICE 2013 6
21 COD GOM UP TO 14,000 2.1 2013 6
22 COD GOM 20000 INQUIRE 2013 6
23 COD GBE ANY 1.5 2013 6
24 HADDOCK GOM 10000 INQUIRE 2013 6
25 HADDOCK GOM UP TO 6,000 0.75 2013 6
26 WHITE HAKE UP TO 100,000 0.3 2013 6
27 0 0 0 2013 6
email_day
2 11
3 11
4 11
5 11
6 11
7 11
8 11
9 11
10 11
11 11
12 11
13 11
14 11
15 11
16 11
17 11
18 11
19 11
20 11
21 11
22 11
23 11
24 11
25 11
26 11
27 11
它在行cursor.executemany(sql_query, exported_data)
上失败,并显示错误
It fails on the line cursor.executemany(sql_query, exported_data)
with the error
TypeError: expecting numeric data
.
我的相关代码:
cursor = con.cursor()
exported_data = [tuple(x) for x in df.values]
#exported_data = [str(x) for x in df.values]
sql_query = ("INSERT INTO ROUGHTABLE(species, date_posted, stock_id, pounds, money, trade_year, trade_month, trade_day, sector_name, ask)" "VALUES(:3, :1, :2, :4, :5, :6, :7, :8 'Sustainable Harvest Sector', '1')")
cursor.executemany(sql_query, exported_data)
con.commit() #commit to database
cursor.close()
con.close()
当我注释exported_data
行并取消注释其下面的行时,它仍然会失败,但是这次出现错误
When I comment the exported_data
line and un-comment the one below it, it still fails, but this time with the error
cx_Oracle.DatabaseError: ORA-01036: illegal variable name/number
研究这些错误,发现它们可能是由于绑定变量,无效的日期格式,试图导出字符串而不是dict等引起的.我不是SQL方面的专家,并且希望帮助解决此问题.
Researching these errors reveal that they could be due to bind variables, invalid date formats, trying to export a string vs a dict, etc. I am not an expert with SQL and would like help solving this.
感谢您的任何帮助.
推荐答案
看起来像数字列中有非数字值,不是吗?添加oracle表定义可以帮助解决问题所在.
Looks like there are non-numeric values in what looks like numeric columns, no? Adding the oracle table definition could assist as to where the issue is.
这篇关于将数据框导出到Oracle:TypeError的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!