[英]How to remove single quotation marks in a column on pandas
如何在我的數據框中刪除 Genre 和 Country 列的單引號?
ID Title Type Year Released Genre Country
0 ts300399 Five Came Back: The Reference Films SHOW 1945 48 'documentary' 'US'
我嘗試了 strip() 但沒有用。
df[['Genre', 'Country']] = df[['Genre', 'Country']].apply(lambda col: col.str.strip("'"))
print(df)
ID Title Type Year Released Genre Country
0 0 ts300399 Five Came Back: The Reference Films SHOW 1945 48 documentary US
假設單引號始終存在:
df[['Genre', 'Country']] = df[['Genre', 'Country']].applymap(lambda x: x[1:-1])
會完成工作並且速度非常快。
選擇感興趣的列並將標點符號替換為“”
df[['Genre','Country']] = df[['Genre','Country']].replace({"$^'|'": ""}, regex=True)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.