Reputation: 103
I'm trying to get just the team name and delete the team records which were attached when I scraped the table. I know I can use rstrip(), but I don't want to enter all of the team records to remove. Any ideas?
# Using Pandas to extract rankings tables
import pandas as pd
tables = pd.read_html(base_site)
# base_site = "http://cbssports.com/college-football/rankings/cbs-sports-ranking/"
rankings=tables[0]
rankings
rankings.drop(['Trend', 'Next Game', 'Unnamed: 5', 'Unnamed: 3'], axis=1)
from that I get:
Rank Team
0 1 LSU 15-0
1 2 Clemson 14-1
2 3 Ohio St. 13-1
3 4 Georgia 12-2
4 5 Oregon 12-2
... ... ...
125 126 New Mexico St. 2-10
126 127 Old Dominion 1-11
127 128 UTEP 1-11
128 129 Massachusetts 1-11
129 130 Akron 0-12
130 rows × 2 columns
Looking to remove the teams' records from the Teams column. Thoughts?
Upvotes: 0
Views: 100
Reputation: 323226
You can do rsplit
df['Team']=df['Team'].str.rsplit(' ', n=1).str[0]
Upvotes: 1