【python pandas】 Dataframe的数据print输出 显示为...省略号

来源:互联网 发布:网络自制抗日剧牺牲 编辑:程序博客网 时间:2024/06/07 00:21

pandas.set_option() 可以设置pandas相关的参数,从而改变默认参数。 打印pandas数据事,默认是输出100行,多的话会输出….省略号。

那么可以添加:

 pandas.set_option('display.max_rows',None)

这样就可以显示全部数据

同样,某一列比如url太长 显示省略号 也可以设置。

pd.set_option('display.max_colwidth',500)

下面以爬取统计之家历史文章为例

# encoding: utf-8import sysreload(sys)sys.setdefaultencoding('utf-8')import pandas as pdfrom lxml import etreeimport requestsimport reurl="https://cosx.org/archives/"html=requests.get(url).contentselector=etree.HTML(html)# print htmldate=[]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
阅读全文
1 0
原创粉丝点击