python - Pandas Dataframe to_CSV instead of copper module -
hello friendly people of stackoverflow,
i need function next code write pandas dataframe generated next code "teams.csv" , without utilize of copper.
except removing lines
import copper
and
copper.project.path = '../../'
what needs changed here?
thank much time
import copper import pandas pd import requests bs4 import beautifulsoup copper.project.path = '../../' url = 'http://espn.go.com/nba/teams' r = requests.get(url) soup = beautifulsoup(r.text) tables = soup.find_all('ul', class_='medium-logos') teams = [] prefix_1 = [] prefix_2 = [] teams_urls = [] table in tables: lis = table.find_all('li') li in lis: info = li.h5.a teams.append(info.text) url = info['href'] teams_urls.append(url) prefix_1.append(url.split('/')[-2]) prefix_2.append(url.split('/')[-1]) dic = {'url': teams_urls, 'prefix_2': prefix_2, 'prefix_1': prefix_1} teams = pd.dataframe(dic, index=teams) teams.index.name = 'team' print(teams) copper.save(teams, 'teams')
python csv pandas beautifulsoup
No comments:
Post a Comment