pandas 相当于 Python 熊猫的 R 视图

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/21834676/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-13 21:42:21  来源:igfitidea点击:

equivalent of R's View for Python's pandas

pythonrpandaspycharm

提问by uday

The Viewis a very useful function to allow me to see cross-section of large data frames in R.

View是一个非常有用的函数,可以让我查看 R 中大型数据框的横截面。

Is there any equivalent of R's Viewfunction for Python's pandas DataFrame?

ViewPython 的 pandas是否有任何等效于 R 的函数DataFrame

I use RStudiofor R and PyCharmfor Python.

RStudio用于 R 和PyCharmPython。

采纳答案by Will

A quicker option might be to set the pandas dataframe so it doesn't line wrap by putting this line of code:

一个更快的选择可能是设置Pandas数据框,这样它就不会通过放置以下代码行来换行:

import pandas
pandas.set_option('expand_frame_repr', False)

I'm using Sublime Text 2 and this is how it looks:

我正在使用 Sublime Text 2,它的外观如下:

Before putting in option(Notice how the output wraps the text around) Before

在放入选项之前(注意输出如何环绕文本) 前

After putting in option(Notice how the output continues) After

放入选项后(注意输出如何继续) 后

Also make sure that 'View' > 'Word Wrap' is not checked.

还要确保未选中“查看”>“自动换行”。

Additionally, you can print out more or less as you need by using head(#)like this:

此外,您可以通过使用head(#)像这样根据需要打印出更多或更少:

mydf = pandas.DataFrame.from_csv('myfile.csv', header=1)
print mydf.head(20) # Prints first 20 lines

Here's some other pandas options:

这里有一些其他的 Pandas 选项:

pandas.set_option('display.max_columns', 0) # Display any number of columns
pandas.set_option('display.max_rows', 0) # Display any number of rows

回答by AffableAmbler

Spyder within Anaconda (or R Studio for Python as I like to call it) gives you the ability to view and sort entire dataframes the same way you would in R using the variable explorer.

Anaconda 中的 Spyder(或我喜欢称之为 Python 的 R Studio)使您能够像在 R 中使用变量资源管理器一样查看和排序整个数据帧。

https://www.continuum.io/

https://www.continuum.io/

enter image description here

在此处输入图片说明

回答by Vishal Sharma

If you are a regular R user and using python also and you like R studio more then I would recommend you to use R Studio to write python scripts. You can use the reticulate library for the same. reticulate::conda_python()will take you to the python console and to write a script, just create new python script from the menu. Next consider the following code written in python:

如果你是一个普通的 R 用户并且也在使用 python 并且你更喜欢 R studio,那么我建议你使用 R Studio 来编写 python 脚本。您可以使用网状库。 reticulate::conda_python()将带您到 python 控制台并编写脚本,只需从菜单中创建新的 python 脚本。接下来考虑以下用python编写的代码:

import pandas as pd
df_python = pd.DataFrame({'num_legs': [2, 4, 8, 0],
               'num_wings': [2, 0, 0, 0],
               'num_specimen_seen': [10, 2, 1, 8]},
              index=['falcon', 'dog', 'spider', 'fish'])

This will create a pandas dataframe df_python

这将创建一个Pandas数据框 df_python

enter image description here

在此处输入图片说明

Now exit from the python console using exitkeyword. Now when you will use py$ then you can access python objects. This can let you use this dataframe in R as well and hence you can view the dataframe also using View(py$df_python)and you will have the following output.

现在使用exit关键字从 python 控制台退出。现在,当您将使用 py$ 时,您就可以访问 python 对象。这也可以让您在 R 中使用此数据框,因此您也可以使用该数据框查看View(py$df_python),您将获得以下输出。

enter image description here

在此处输入图片说明

Keep Coding!

继续编码!

回答by Paul H

In ipython (notebook or qtconsole), you can do:

在 ipython(笔记本或 qtconsole)中,您可以执行以下操作:

from IPython.display import HTML
HTML(myDataFrame.to_html())

Doesn't help with pycharm, but it may be worth pursuing.

对 pycharm 没有帮助,但它可能值得追求。