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