如何阻止我的 pandas 数据表在打印时被截断? [英] How to stop my pandas data table from being truncated when printed?
本文介绍了如何阻止我的 pandas 数据表在打印时被截断?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我编写了读取两个字符串的代码,然后将它们比较相似的单词.然后将产生一个带有数据的表格.
I've written code that reads in two strings then compares them for similar words. A table is then produced with the data.
我的问题是它不断分裂为两个.我需要对此进行纠正,以便能够将其合并到HTML中.我将不胜感激,在此先感谢您!:)
My problem is that it keeps splitting into two. I need to rectify this to be able to incorporate this into HTML. I'd appreciate any help, and thanks in advance! :)
我也尝试只打印第一行.
I tried printing just the top row also.
完整代码:
import string
from os import path
import pandas as pd
pd.set_option('display.max_columns', None) #prevents trailing elipses
pd.set_option('display.max_rows', None)
import os.path
BASE = os.path.dirname(os.path.abspath(__file__))
file1 = open(os.path.join(BASE, "samp.txt"))
sampInput=file1.read().replace('\n', '')
file2 = open(os.path.join(BASE, "ref.txt"))
refInput=file2.read().replace('\n', '')
sampArray = [word.strip(string.punctuation) for word in sampInput.split()]
refArray = [word.strip(string.punctuation) for word in refInput.split()]
out=pd.DataFrame(index=sampArray,columns=refArray)
for i in range(0, out.shape[0]): #from 0 to total number of rows
for word in refArray: #for each word in the samplearray
df1 = out.iloc[0, 0:16].copy()
top = out.ix[:1, :17]
out.ix[i,str(word)] = out.index[i].count(str(word))
#print(out)
print(top)
#print(df1)
推荐答案
您可以设置有关如何显示数据框的选项:
You can set options on how to display your dataframes:
pd.set_option('display.max_rows', 500)
pd.set_option('display.max_columns', 500)
pd.set_option('display.width', 150)
如果您在打印任何内容之前添加了此内容,则数据框将以您期望的格式打印
If you add this before you print anything, your dataframe will be printed in the format you'd expect
这篇关于如何阻止我的 pandas 数据表在打印时被截断?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文