繁体   English   中英

在 pandas 的特定行中运行代码时出现语法错误

[英]Getting syntax error while running the code in a particular line in pandas

它向我显示了这一行的错误:

name = sel.xpath("//*[@class = "inline t-24 t-black t-normal break-words"]/text()").extract_first().split()

错误:

File "<ipython-input-9-f8d78586cc1a>", line 7
    name = sel.xpath("//*[@class = "inline t-24 t-black t-normal break-words"]/text()").extract_first().split()
                                         ^
SyntaxError: invalid syntax

试试这个:

name = sel.xpath('//*[@class = "inline t-24 t-black t-normal break-words"]/text()1).extract_first().split()

更一般地说,您可以使用单引号或双引号在 python 中定义字符串:

str1 = "hi there"
str2 = 'goodbye'

但是,如果要在内部定义带有单引号/双引号的字符串,则需要在外部使用另一种类型的字符串定义:

str3 = "he said: `I quote with single quotes`"
str4 = 'she said: "I quote with double quotes"'

print(str3) # yields he said: `I quote with single quotes`
print(str4) # yields she said: "I quote with double quotes"

您需要交替使用单引号和双引号以使字符串保持一致。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM