![](/img/trans.png)
[英]I am getting an error while i am running a function in pandas dataframe.I am getting invalid syntax for the first line of the function
[英]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.