问题
I've written code that reads in two strings then compares them for similar words. A table is then produced with the data.
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.
Full code:
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)
回答1:
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
来源:https://stackoverflow.com/questions/51325601/how-to-stop-my-pandas-data-table-from-being-truncated-when-printed