作者drunkofwind ()
看板Python
标题[问题] 回圈dataframe资料的汇出
时间Tue Jan 30 20:31:36 2018
大家好,
写了一个小爬虫,因为撷取的资料为dataframe,回圈结果都只输出最後一次,
请问该如何让每次迭代的结果,按照row堆叠下去呢?
-------------------------------------------------------------
urls =
['
http://www.fishbase.org/popdyn/PopGrowthList.php?ID=22903&GenusName=Abbottina&SpeciesName=rivularis&fc=122',
'
http://www.fishbase.org/popdyn/PopGrowthList.php?ID=972&GenusName=Ablennes&SpeciesName=hians&fc=207',
'
http://www.fishbase.org/popdyn/PopGrowthList.php?ID=268&GenusName=Abramis&SpeciesName=brama&fc=122']
for url in urls:
QWQ = re.findall(r"=(\w+)&", url)
fish = pd.read_html(url)[1].assign(id=QWQ[0],gnema=QWQ[1],snema=QWQ[2])
pd.concat([fish], axis=0)
print(fish)
--------------------------------------------------------------------------------
--
※ 发信站: 批踢踢实业坊(ptt.cc), 来自: 140.112.70.50
※ 文章网址: https://webptt.com/cn.aspx?n=bbs/Python/M.1517315501.A.67D.html
1F:→ painkiller: 你的'fish = '会把旧的data frame洗掉 01/31 00:33
2F:→ drunkofwind: 请问 那该怎麽放呢? 01/31 09:03
3F:→ painkiller: 回圈外 'fish_all = ' 先读第一个url 01/31 09:15
4F:→ painkiller: 回圈内 fish_all = pd.concat([fish_all, fish] ... 01/31 09:16
5F:→ painkiller: 或是append 01/31 09:16
6F:→ drunkofwind: 谢谢P大解答~~~感激不尽! 01/31 10:11