![](/img/trans.png)
[英]How to remove first part of URL string in column value with Pandas?
[英]Remove part of a string value from a column in pandas
使用 Pandas 數據框並希望能夠在以“\”開頭的 Players 列的每一行中刪除名稱 ID
python 和 pandas 的新手,假設這可能是用一兩行代碼就能輕松解決的問題,但我似乎無法破解它。
file_open=open('2000_2019_All_Pro.csv')
df_AP2000 = pd.read_csv(file_open)
df_counts = df_AP2000['Player'].value_counts()
df_counts.to_frame()
df_counts.drop(df_counts.index[[0]], axis=0, inplace=True)
df_counts.reset_index().rename(columns={'index': 'Player', 'Player': 'Frequency'})
嘗試將字符串操作與split
結合使用:
df_counts['Player'] = df_counts['Player'].str.split('\\').str[0]
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.