预期unicode参数,得到'str'

时间:2018-12-13 21:49:05

标签: python pandas python-2.7

我正在使用python 2.7.12。运行pd.__version__返回u'0.19.0'。

我正在使用一个称为达尔马提亚的模块。对于其中一个功能,一旦我按原样运行文档中提供的内容,就会收到错误消息:

wm.update_participant_set('all_participants', participant_df.index)
TypeError: unicode argument expected, got 'str'

我有点怀疑,这可能是由于我使用的pandas或python版本造成的。运行participant_df.index返回:

Index([u'100_2', u'101_3', u'102_2', u'103_3', u'104_2', u'105_2', u'106_4',
   u'107_4', u'108_4', u'109_1',
   ...
   u'91_2', u'92_3', u'93_2', u'94_4', u'95_4', u'96_3', u'97_2', u'98_3',
   u'99_1', u'9_1'],
  dtype='object', name=u'participant_id', length=523)`

我也尝试过将其提交为.astype(unicode).index.values。我想我真的不知道如何进一步解决此问题。有什么想法吗?

编辑以包含回溯

Traceback (most recent call last):
  File "<stdin>", line 2, in <module>
  File "/gpfs/fs1/home/jrouhana/jrouhana/lib/python2.7/site-packages/dalmatian/wmanager.py", line 1045, in update_participant_set
    self.update_entity_set('participant', participant_set_id, participant_ids)
  File "/gpfs/fs1/home/jrouhana/jrouhana/lib/python2.7/site-packages/dalmatian/wmanager.py", line 1030, in update_entity_set
    self.upload_entities('{}_set'.format(etype), set_df, index=False)
  File "/gpfs/fs1/home/jrouhana/jrouhana/lib/python2.7/site-packages/dalmatian/wmanager.py", line 164, in upload_entities
    df.to_csv(buf, sep='\t', index=index)
  File "/modules/EasyBuild/software/pandas/0.19.0-foss-2016b-Python-2.7.12/lib/python2.7/site-packages/pandas-0.19.0-py2.7-linux-x86_64.egg/pandas/core/frame.py", line 1381, in to_csv
    formatter.save()
  File "/modules/EasyBuild/software/pandas/0.19.0-foss-2016b-Python-2.7.12/lib/python2.7/site-packages/pandas-0.19.0-py2.7-linux-x86_64.egg/pandas/formats/format.py", line 1475, in save
    self._save()
  File "/modules/EasyBuild/software/pandas/0.19.0-foss-2016b-Python-2.7.12/lib/python2.7/site-packages/pandas-0.19.0-py2.7-linux-x86_64.egg/pandas/formats/format.py", line 1562, in _save
    self._save_header()
  File "/modules/EasyBuild/software/pandas/0.19.0-foss-2016b-Python-2.7.12/lib/python2.7/site-packages/pandas-0.19.0-py2.7-linux-x86_64.egg/pandas/formats/format.py", line 1530, in _save_header
    writer.writerow(encoded_labels)
TypeError: unicode argument expected, got 'str'

1 个答案:

答案 0 :(得分:2)

我遇到了同样的错误,代码是用python 3编写的,但是我是用python 2运行它的。 所以贴在python 3上对我有用。