python blaze(pandas)无法安装转换用户dtype <i8

时间:2015-05-07 17:16:43

标签: python postgresql pandas blaze

=“”

我想从{{uk.txt文件中读取import blaze as bz from odo import odo dataPath = 'uk.txt' myData = bz.Data(dataPath, sep='\t') out = odo(myData, 'postgresql://postgres:postgres@localhost:5432/blaze_test::uk_geonames') 文件3}}使用python uk nga geonames download然后blaze将其插入到Postgresql数据库中。

代码是:

ValueError: cannot safely convert passed user dtype of <i8 for object dtyped data in column 0

我得到的错误dtype我认为我理解为含义&#34;数据类型无法转换为插入数据库&#34;

我应该强迫RC UFI UNI LAT LONG DMS_LAT DMS_LONG MGRS JOG FC DSG PC CC1 ADM1 POP ELEV CC2 NT LC SHORT_FORM GENERIC SORT_NAME_RO FULL_NAME_RO FULL_NAME_ND_RO SORT_NAME_RG FULL_NAME_RG FULL_NAME_ND_RG NOTE MODIFY_DATE DISPLAY NAME_RANK NAME_LINK TRANSL_CD NM_MODIFY_DATE 1 380952 475802 54.086111 -6.655556 540510 -63920 29UPV5334795644 NN29-06 H STM EI,UK EI,UK N Clarebane CLAREBANERIVER Clarebane River Clarebane River CLAREBANERIVER Clarebane River Clarebane River 2014-06-27 1,2,3 2 等于什么吗?我该如何解决这个问题?

该文件的示例输入是:

ScriptManager.RegisterStartupScript(this, GetType(), "myFunction", "myFunction();", true);   //in code behind file

1 个答案:

答案 0 :(得分:5)

由于某种原因,未正确推断标头。您可以像这样传递infer_header关键字参数:

In [12]: from blaze import Data

In [13]: from odo import CSV, odo

In [14]: d = Data(CSV('uk.txt', sep='\t', has_header=True))

In [15]: d.head(5)
Out[15]:
   RC     UFI     UNI        LAT      LONG  DMS_LAT  DMS_LONG  \
0   1  380952  475802  54.086111 -6.655556   540510    -63920
1   1  380952  475801  54.086111 -6.655556   540510    -63920
2   1  380954  475805  54.104722 -6.648889   540617    -63856
3   1  380955  475806  54.098056 -6.644167   540553    -63839
4   1  380958  475810  54.040556 -6.614444   540226    -63652

              MGRS      JOG FC      ...          SORT_NAME_RG  \
0  29UPV5334795644  NN29-06  H      ...        CLAREBANERIVER
1  29UPV5334795644  NN29-06  H      ...             CLAREBANE
2  29UPV5371497729  NN29-06  H      ...           ALINA LOUGH
3  29UPV5404796997  NN29-06  H      ...          CORLISSLOUGH
4  29UPV5620690667  NN29-06  H      ...          DRUMBOYLOUGH

      FULL_NAME_RG  FULL_NAME_ND_RG NOTE MODIFY_DATE DISPLAY NAME_RANK  \
0  Clarebane River  Clarebane River  NaN  2014-06-27   1,2,3         2
1        Clarebane        Clarebane  NaN  2014-06-27   1,2,3         1
2     Alina, Lough     Alina, Lough  NaN  2014-06-27   1,2,3         1
3    Corliss Lough    Corliss Lough  NaN  2014-06-27   1,2,3         1
4    Drumboy Lough    Drumboy Lough  NaN  2014-06-27   1,2,3         1

  NAME_LINK TRANSL_CD NM_MODIFY_DATE
0       NaN       NaN     2014-06-27
1       NaN       NaN     2014-06-27
2       NaN       NaN     2014-06-27
3       NaN       NaN     2014-06-27
4       NaN       NaN     2014-06-27

[5 rows x 34 columns]

之后,只需odo进入所需的表格:

In [16]: t = odo(d, 'postgresql://localhost::uk')

In [17]: uk = Data(t)

In [19]: uk.head(5)
Out[19]:
   RC     UFI     UNI        LAT      LONG  DMS_LAT  DMS_LONG  \
0   1  380952  475802  54.086111 -6.655556   540510    -63920
1   1  380952  475801  54.086111 -6.655556   540510    -63920
2   1  380954  475805  54.104722 -6.648889   540617    -63856
3   1  380955  475806  54.098056 -6.644167   540553    -63839
4   1  380958  475810  54.040556 -6.614444   540226    -63652

              MGRS      JOG FC      ...          SORT_NAME_RG  \
0  29UPV5334795644  NN29-06  H      ...        CLAREBANERIVER
1  29UPV5334795644  NN29-06  H      ...             CLAREBANE
2  29UPV5371497729  NN29-06  H      ...           ALINA LOUGH
3  29UPV5404796997  NN29-06  H      ...          CORLISSLOUGH
4  29UPV5620690667  NN29-06  H      ...          DRUMBOYLOUGH

      FULL_NAME_RG  FULL_NAME_ND_RG NOTE MODIFY_DATE DISPLAY NAME_RANK  \
0  Clarebane River  Clarebane River  NaN  2014-06-27   1,2,3         2
1        Clarebane        Clarebane  NaN  2014-06-27   1,2,3         1
2     Alina, Lough     Alina, Lough  NaN  2014-06-27   1,2,3         1
3    Corliss Lough    Corliss Lough  NaN  2014-06-27   1,2,3         1
4    Drumboy Lough    Drumboy Lough  NaN  2014-06-27   1,2,3         1

  NAME_LINK TRANSL_CD NM_MODIFY_DATE
0       NaN       NaN     2014-06-27
1       NaN       NaN     2014-06-27
2       NaN       NaN     2014-06-27
3       NaN       NaN     2014-06-27
4       NaN       NaN     2014-06-27

[5 rows x 34 columns]