[英]Python how to strip end colons of a string in dataframe
I have dataframe consisting a column of strings.我有包含一列字符串的数据框。
intcontn1 = [1,2,3,4]
df =
data1 data2 ... data5 test
2019-09-26 14:53:00 72.847746 6.134 ... 24.175877 intcontn1
2019-09-26 16:13:00 76.124547 3.426 ... 39.138517 intcontn1
2019-09-26 16:53:00 77.714545 1.984 ... 39.868317 intcontn1
print(df['test'].tolist())
['intcontn1', 'intcontn1', 'intcontn1']
This looks fine but I want to print without quotes something like this below这看起来不错,但我想在不带引号的情况下打印以下内容
print(df['test'].tolist())
[intcontn1,intcontn1,intcontn1]
How to get this?如何得到这个?
Do you mean you want to print without the apostrophes ( '
)?您的意思是要在没有撇号 (
'
) 的情况下进行打印吗? If so, you could explicitly convert the list to a string and replace()
the apostrophes with a blank string:如果是这样,您可以将列表显式转换为字符串并
replace()
空字符串replace()
撇号:
print(str(df['test'].tolist()).replace("'", ""))
[intcontn1, intcontn1, intcontn1]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.