Is there a simple way to remove multiple spaces in a string?

后端 未结 29 1329
星月不相逢
星月不相逢 2020-11-22 08:17

Suppose this string:

The   fox jumped   over    the log.

Turning into:



        
29条回答
  •  南笙
    南笙 (楼主)
    2020-11-22 09:03

    You can also use the string splitting technique in a Pandas DataFrame without needing to use .apply(..), which is useful if you need to perform the operation quickly on a large number of strings. Here it is on one line:

    df['message'] = (df['message'].str.split()).str.join(' ')
    

提交回复
热议问题