东风看起来像
type
0 a
1 b
2 c
输出应该看起来像
string="'a','b','c'"
我已经使用df.type.str.cat(sep=',')
增加,两者之间却怎么加引号的每个元素?
string = ','.join("'"+df['type']+"'")
要么:
string = ("'"+df['type']+"'").str.cat(sep=',')
string
"'a','b','c'"
另一种选择是,与format
和apply
使用sum
:
result = df.type.apply("'{}',".format).sum()[:-1]