Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to stop my pandas data table from being truncated when printed?

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.

top row

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)
like image 243
Brndn Avatar asked Jul 13 '18 12:07

Brndn


People also ask

How do I view full DataFrame in Jupyter?

How do I view full dataset in Jupyter notebook? To show all the columns of a pandas dataframe in jupyter notebook, you can change the pandas display settings. Let's go ahead and set the max_columns display parameter to None so that all the columns are displayed.

How do I print Max rows in Pandas?

Call pandas. set_option("display. max_rows", max_rows, "display. max_columns", max_cols) with both max_rows and max_cols as None to set the maximum number of rows and columns to display to unlimited, allowing the full DataFrame to be displayed when printed.

What is the correct way to print the first 10 rows of a panda DataFrame?

Use pandas. DataFrame. head(n) to get the first n rows of the DataFrame. It takes one optional argument n (number of rows you want to get from the start).


1 Answers

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

like image 127
Jeroen Avatar answered Sep 18 '22 18:09

Jeroen