简体   繁体   English

如何在python中将符号(“%”)连接为整数?

[英]How can I concatenate symbol (“%”) to integer value in python?

I am facing an issue here. 我在这里面临一个问题。 I have a Dataframe column whose values I need to put as value+% ie say 10%, 15% etc. 我有一个Dataframe列,我需要将其值设置为value+%例如10%, 15%等。

However, I am able to put the values as string type in the excel sheet after writing but while I plot the graph, the value is being considered as a string and hence the chart is not getting generated. 但是,我可以在写入后将值作为字符串类型放入excel表中,但是在绘制图形时,该值被视为字符串,因此不会生成图表。

I need to paste the value with the % symbol in the concerned column as well as I need to plot the graph while writing to the excel sheet. 我需要在相关列中粘贴带有%符号的值,以及在写入excel工作表时绘制图表。

Any solution for this?? 任何解决方案?

Thanks in advance. 提前致谢。

For writing the value in excel you can use 要在excel中编写值,您可以使用

str(value) + '%'

While plotting graph access the values by slicing the last character(%) and convert it to number by using eval function. 在绘制图形时,通过切片最后一个字符(%)来访问值,然后使用eval函数将其转换为数字。

eval(value[:-1])

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

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