简体   繁体   English

如何从控制台打印/提取所有行和列?

[英]how to print/extract all rows and columns from the console?

i want to print or extract all columns and rows from my result data. 我想从结果数据中打印或提取所有列和行。 The data is 61 rows and columns. 数据为61行和列。 The console displays like 6 or 7 columns and rows and fills the rest with dots but I need to obtain all the numbers. 控制台显示6或7列和7行,其余的点用点填充,但我需要获取所有数字。 I uploaded an image of my data in the console. 我在控制台中上传了我的数据图像。 Image of the data with dots and missing columns and rows. 带有点,缺少的列和行的数据图像。

Your help is deeply appreciated! 非常感谢您的帮助!

Check out the Pandas documentation . 查阅Pandas文档 You should be able to set display for max_rows and max_columns like so: 您应该能够像这样设置max_rowsmax_columns显示:

import pandas as pd

pd.set_option("display.max_rows", None)
pd.set_option("display.max_columns", None)

As noted in the docs, None sets the limit to be unlimited. 如文档中所述,“ None将限制设置为无限。 Warning: you're going to fill your console up very quickly with large frames. 警告:您将很快用大型框架填充控制台。

If you have particularly wide columns, you may need to tinker with display.max_colwidth . 如果列特别宽,则可能需要修改display.max_colwidth

I ran into a similar situation recently. 最近我遇到了类似情况。 I just needed a quick and easy way to just look at specific columns. 我只需要一种快速简便的方法来查看特定的列。

Dependency Warning : Pandoc must be installed. 相关性警告 :必须安装Pandoc

This code includes the creation of a 61x61 data frame. 此代码包括创建61x61数据帧。 A subprocess is opened. 将打开一个子进程。 Pandocs converts the data frame from a LaTex format to a Markdown table format. Pandocs将数据帧从LaTex格式转换为Markdown表格式。 awk is used to slice columns from the output. awk用于从输出中切片列。 less paginates the output. less分页输出。

To examine, for example, to examine the 10th column, I executed the following in the terminal: python print_pandas.py | awk '{ print $10 }' | less 例如,要检查第10列,我在终端中执行了以下命令: python print_pandas.py | awk '{ print $10 }' | less python print_pandas.py | awk '{ print $10 }' | less

Change the $10 value accordingly. 相应地更改$10值。

# contents of print_pandas.py
from subprocess import PIPE, Popen
import shlex

import numpy as np
import pandas as pd

# Create a large random data frame.
df = pd.DataFrame([np.random.uniform(size=61) for _ in range(61)])

s = df.to_latex()
p = Popen(shlex.split('pandoc -f latex -t markdown'),
          stdin=PIPE, stdout=PIPE)
stdoutdata, _ = p.communicate(input=s.encode("utf-8"))
print(stdoutdata.decode("utf-8"))

端子输出

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM