从python中的字符串中删除text:u [英] Remove text:u from strings in python

查看:579
本文介绍了从python中的字符串中删除text:u的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用xlrd库将值从excel文件导入到python列表中. 我在excel文件中有一列,并且按行提取数据. 但是问题是我在列表中得到的数据是

I am using xlrd library to import values from excel file to python list. I have a single column in excel file and extracting data row wise. But the problem is the data i am getting in list is as

list = ["text:u'__string__'","text:u'__string__'",.....so on]

我如何从中删除此text:u以获得带有字符串的自然列表?

How can i remove this text:u from this to get natural list with strings ?

在这里使用python2.7进行编码

code here using python2.7

book = open_workbook("blabla.xlsx")
sheet = book.sheet_by_index(0)
documents = []

for row in range(1, 50): #start from 1, to leave out row 0
    documents.append(sheet.cell(row, 0)) #extract from first col

data = [str(r) for r in documents]
print data

推荐答案

对项目进行迭代,并从每个单词中删除多余的字符:

Iterate over items and remove extra characters from each word:

s=[]   
for x in list:
    s.append(x[7:-1]) # Slice from index 7 till lastindex - 1

这篇关于从python中的字符串中删除text:u的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆