从Pandas列文本中删除Unicode

时间:2017-07-07 21:10:34

标签: python pandas unicode

我正在尝试确定列表中的数据是否在数据帧列中。我是Pandas的新手并且一直在努力解决这个问题,所以目前我正在将感兴趣的数据框列转换为列表。但是,当我df.tolist()时,列表中包含一串字符串的unicode。当我试图将其与另一个不在unicode中的列表中的文本进行比较时,我遇到了问题。

我试图将另一个列表转换为unicode但是列表中的项目类似于' [" item"]'没有帮助。我也尝试从数据帧中删除unicode但只是出错。我不能迭代,因为熊猫告诉我数据帧要长时间迭代。以下是我的代码:

SDC_wb = pd.ExcelFile('C:\ BLeh')
df = SDC_wb.parse(SDC_wb.sheet_names[1], header = 1)

def Follower_count(filename):
    filename = open(filename)
    reader = csv.reader(filename)

    handles = df['things'].tolist()

    print handles

    dict1 = {}

    for item in reader:
        if item in handles:
            user = api.get_user(item)
            dict1[item] = user.Follower_count

    newdf = pd.DataFrame(dict1)
    newdf.to_csv('test1.csv', encoding='utf-8')

以下是数据框中的列表:

 [u'@Mastercard', u'@Visa', u'@AmericanExpress', u'@CapitalOne']

这是x = [some_list中s的unicode(s)]的样子:

u"['@HomeGoods']", u"['@pier1']", u"['@houzz']", u"['@InteriorDesign']", u"['@zulily']"]

当然,这些并不是为了检查" in"需求。因此,我需要一种从:

转换.tolist()对象的方法
[u'@Mastercard', u'@Visa', u'@AmericanExpress', u'@CapitalOne']

为:

[@Mastercard, @Visa, @AmericanExpress, @CapitalOne] 

这样handle函数中的for项将看到类似的句柄。

感谢您的帮助。

0 个答案:

没有答案
相关问题