This question already has answers here:
Remove unwanted parts from strings in a column
                                
                                    (9个答案)
                                
                        
                                6个月前关闭。
            
                    
我有一个数据框df

        workhours
0       0 days 01:45:13.250000000
1       0 days 04:23:56.723404255
2       0 days 07:11:01.688888888
3       0 days 06:02:48.160000000
4       0 days 06:27:57.280000000
5       0 days 07:00:26.551020408
6       0 days 09:04:01.039215686
7       0 days 08:50:11.941176470
8       0 days 07:30:59.725490196
...


我只想拥有小时,而不是“ =天”。
如何从每一行删除它?

最佳答案

试试这个:

import re

df["workhours"] = df["workhours"].apply(lambda x: re.sub("\d+ days ", "", x))

关于python - 如何删除一列中每一行的相同单词? ,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/57723843/

10-16 22:47