loading a csv with pandas results in empty fields for numpy values while using converter

喜夏-厌秋 提交于 2020-04-17 22:14:09

问题


loading a csv file with pandas which store numpy arrays and strings, results in empty fields for the numpy values.

As nicely explained here, I load the csv with a converter as the numpy values are converted into strings.

def converter(instr):
    return np.fromstring(instr[1:-1],sep=' ')

myFile = pd.read_csv('./EMBEDDINGS_224.csv', converters={'Embedding':converter}) 

The result per row is just

[]

The original 'Embedding' entry looks like this.

[[0.58197206 2.53598    0.         ... 0.6681144  0.08705447 2.4330063 ]]

All other entries are actually in string format, so that should be fine.

I tried also to load with dtype=np.float32 and np.float64. This resulted in an error:

ValueError: could not convert string to float: '[[0.58197206 2.53598
0. ... 0.6681144 0.08705447 2.4330063 ]]'

Thank you for your help, keep healthy.

来源:https://stackoverflow.com/questions/60960170/loading-a-csv-with-pandas-results-in-empty-fields-for-numpy-values-while-using-c

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!