Pandas Dataframe to_CSV而不是铜模块

时间:2014-10-21 02:10:29

标签: python csv pandas beautifulsoup

你好友好的stackoverflow人,

我需要一个函数用于以下代码,将以下代码生成的pandas数据帧写入" teams.CSV" ,不使用铜。

除了删除行

 import copper

copper.project.path = '../../'

这里需要改变什么?

非常感谢你的时间

import copper
import pandas as pd
import requests
from 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 = []
for table in tables:
lis = table.find_all('li')
for 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')

0 个答案:

没有答案