np.nan is an invalid document, expected byte or unicode string.

Posted smartwhite

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了np.nan is an invalid document, expected byte or unicode string.相关的知识,希望对你有一定的参考价值。

ValueError                                Traceback (most recent call last)
<ipython-input-12-1dc462ae8893> in <module>()
     15     print(‘cv prepared!‘)
     16     return df_x.astype(np.float64)
---> 17 df_test = get_feature(test_data,all_table,ready_cols,vec_col)
     18 df_train = get_feature(train_data,all_table,ready_cols,vec_col)

<ipython-input-12-1dc462ae8893> in get_feature(df, all_data, cols, vec_col)
      9     cv=CountVectorizer()
     10     for feature in vec_col:
---> 11         cv.fit(all_data[feature])
     12         df_a = cv.transform(df[feature])
     13         df_x = sparse.hstack((df_x, df_a))

 

def get_feature(df,all_data,cols,vec_col):
  enc = OneHotEncoder()
  df_x=np.int64(df[cols])
  cv=CountVectorizer()
  for feature in vec_col:
    cv.fit(all_data[feature])
    df_a = cv.transform(df[feature])
    df_x = sparse.hstack((df_x, df_a))
    print(‘Done Feature ‘+ str(feature))
  print(‘cv prepared!‘)
  return df_x.astype(np.float64)

 

原因分析:我的all_data中存在nan的数据,我在数据读入的时候使用了all_table.fillna(-1),我理解只会填充空值,但是all_table中原本为nan的值,不会改变。改为all_table.fillna(-1),可执行。

 











以上是关于np.nan is an invalid document, expected byte or unicode string.的主要内容,如果未能解决你的问题,请参考以下文章

TypeError: ‘encoding‘ is an invalid keyword argument for this function

TypeError: ‘encoding‘ is an invalid keyword argument for this function

TypeError: ‘encoding‘ is an invalid keyword argument for this function

UnhandledPromiseRejectionWarning: TypeError [INVALID_TYPE]: Supplied roles is not an Role, Snowflake

TypeError: 'encoding' is an invalid keyword argument for this function

Column '表名.某列名' is invalid in the select list because it is not contained in either an aggregate f