![](/img/trans.png)
[英]complex dataframe filtering request on the last occurence of a value in Panda/Python [EDIT]
[英]Last occurence of comma in python dataframe
请帮助我在最后一次出现逗号时用 & 替换逗号
DF['味精'] =
0 20.00,20.00 1 4.00,3.00,2.00 2 100.00 3 10.00,70.00,10.00 4 10.00,10.00,10.00,10.00,10.00,10.00 5 99.00 6 50.00,50.00,50.00 7 70.00 8 10.00,20.00,20.00,65.00,65.00
output 是:
0 20.00,20.00 1 4.00,3.00&2.00 2 100.00 3 10.00,70.00&10.00 4 10.00,10.00,10.00,10.00,10.00&10.00 5 99.00 6 50.00,50.00,50.00 770.00 8 10.00,20.00&65.00&65.00
如果逗号出现次数超过 2 次,则在 dataframe 中的 output 中预期请帮助我
假设它是一个干净的数字列表,您可以将其更改为如下字符串:
list_of_numbers = [1, 2, 3, 4]
print(', '.join([str(i) for i in list_of_numbers[:-1]]) + f" & {list_of_numbers[-1]}")
给
1、2、3 和 4
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.