python - 如何阻止我的熊猫数据表在打印时被截断?
问题描述
我编写了读取两个字符串的代码,然后将它们进行比较以获得相似的单词。然后用数据生成一个表。
我的问题是它一直分成两部分。我需要纠正这一点才能将其合并到 HTML 中。我将不胜感激任何帮助,并在此先感谢!:)
我也尝试只打印第一行。
完整代码:
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)
解决方案
您可以设置有关如何显示数据框的选项:
pd.set_option('display.max_rows', 500)
pd.set_option('display.max_columns', 500)
pd.set_option('display.width', 150)
如果您在打印任何内容之前添加它,您的数据框将以您期望的格式打印
推荐阅读
- sql-server - 在子查询中使用 if 子句设置更新值
- r - 如何在rstudio中将日期拆分为年、月、日列?
- swift - Swift Int 数组每 3 个元素总和
- c - 无法解决 CentOS 8.1 上小型 C 程序的链接器错误
- python - 'login' 在 / Reverse 处出现错误 NoReverseMatch,但未找到任何参数。尝试了 1 种模式:['accounts/$login/$']
- c++ - 我不知道如何在不将其连接到 arduino 上的 pin 0 的情况下制作 fade = 0
- javascript - 如何解释我收到的以下错误?
- php - PHP e.preventDefault 导致 isset($_POST['submit']) 为假,$img['name'] 为空
- google-cloud-dataflow - Beam/Dataflow:了解为什么批处理作业在 Stateful Pardo 步骤之前停止
- sql - SQL (Redshift) - 查找连续数字