![](/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.