0

I have an excel file (xlsx). The values are read as unicode values.

wb = xlrd.open_workbook('file.xlsx')
sh = wb.sheet_by_index(0)
first_column = sh.col_values(0)
snd_column = sh.col_values(1)

Output is in the form of:

first_column=['', u'here', u'here i am', u'where', u'where i am']
snd_column=['', u'20 km', ' ', u'10 km', u'23 km']

Empty cells are read as normal empty strings.

How do I get output/read the file directly in strings form. like

first_coulmn=['', 'here', 'here i am', 'where', 'where i am']
snd_coulmn=['', '20 km', ' ', '10 km', '23 km']

I am looking are computationally effective method. Any tips?

4

3 回答 3

0

您可以使用 str() 函数将 unicode 转换为字符串。这就是你要问的吗?

于 2013-03-11T20:31:36.737 回答
0

How about:

first_column = [str(v) for v in first_column]
于 2013-03-11T20:30:26.900 回答
-1
worksheet.cell_value(row_index,coluna_sample) gives me --> u'7690088954'
str(worksheet.cell(row_index,coluna_sample).value) gives me --> '7690088954'
As sugested by aestrivex
于 2017-04-06T19:45:27.197 回答