【问题标题】:TypeError: unsupported operand type(s) for +: 'float' and 'unicode类型错误:+ 不支持的操作数类型:'float' 和 'unicode
【发布时间】:2019-03-08 16:39:16
【问题描述】:

目前我正在尝试将域列表与特定路径结合起来。尝试将域与特定路径组合时出现错误。

TypeError:+ 的不支持的操作数类型:“float”和“unicode”

我目前正在阅读两个 Excel 文档。代码如下:

import pandas as pd
import urllib


apps = pd.read_excel("test.xlsx", "Sheet1")
pdirs= pd.read_excel("dirs.xlsx", "Sheet1")

urls = apps['Domains'].values.tolist()
dirs = pdirs['DIR'].values.tolist() 

for websites in urls:
    for directory in dirs:
        testURL= websites + directory
        print (testURL)

网站格式如 test.test.com,目录变量格式如 /test。

有什么想法吗?

【问题讨论】:

  • 读取错误。您不能将浮点数(数字)和 unicode(字符串)相加。显然,websites 变量有一个浮点值,directory 有一个字符串。

标签: python python-2.7


【解决方案1】:

你最好对它进行类型转换。我是说 str(websites) + str(directory)

【讨论】:

    猜你喜欢
    • 2021-06-16
    • 2021-03-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-12-03
    • 1970-01-01
    • 2018-12-26
    • 1970-01-01
    相关资源
    最近更新 更多