pandas.set_option() 可以设置pandas相关的参数,从而改变默认参数。 打印pandas数据事,默认是输出100行,多的话会输出….省略号。
那么可以添加:
pandas.set_option('display.max_rows',None)
这样就可以显示全部数据
同样,某一列比如url太长 显示省略号 也可以设置。
pd.set_option('display.max_colwidth',500)
下面以爬取统计之家历史文章为例
# encoding: utf-8
import sys
reload(sys)
sys.setdefaultencoding('utf-8')
import pandas as pd
from lxml import etree
import requests
import re
url="https://cosx.org/archives/"
html=requests.get(url).content
selector=etree.HTML(html)
# print html
date=[]
url_list=[]
title=[]
date1=re.findall('<span class="date">(.*?)</span>',html,re.S)
for each in date1:
# print each
date.append(each)
url_list1=selector.xpath('/html/body/div/article/main/ul/li/a/@href')
for each in url_list1:
# print each
# print "https://cosx.org"+str(each)
url_list.append("https://cosx.org" + str(each))
title1 = selector.xpath('/html/body/div/article/main/ul/li/a/text()')
for each in title1:
# print each
title.append(each)
print len(url_list),len(date),len(title)
pd.set_option('display.max_rows',None)
pd.set_option('display.max_colwidth',500)
df=pd.DataFrame({"日期":date,"标题":title,"链接":url_list})
print df