pandas PyCharm 中未显示数据帧头
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/39905931/
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
Dataframe head not shown in PyCharm
提问by user1774127
I have the following code in PyCharm
我在 PyCharm 中有以下代码
import pandas as pd
import numpy as np
import matplotlib as plt
df = pd.read_csv("c:/temp/datafile.txt", sep='\t')
df.head(10)
I get the following output:
我得到以下输出:
Process finished with exit code 0
I am supposed to get the first ten rows of my datafile, but these do not appear in PyCharm.
我应该得到我的数据文件的前十行,但这些没有出现在PyCharm.
I checked the Project interpreter and all settings seem to be alright there. The right packages are installed (numpy, pandas, matplotlib) under the right Python version.
我检查了项目解释器,所有设置似乎都没有问题。在正确的 Python 版本下安装了正确的包(numpy、pandas、matplotlib)。
What am I doing wrong? Thanks.
我究竟做错了什么?谢谢。
回答by furas
PyCharmis not Python Shellwhich automatically prints all results. You have to use print()to display anything.
PyCharm不是Python Shell自动打印所有结果。你必须使用print()来显示任何东西。
print(df.head(10))
回答by Kenny Monar
I did File-Invalidate Caches/Restart Option Invalidate and after that I was able to get the head:
我做了 File-Invalidate Caches/Restart Option Invalidate ,之后我能够得到头:


回答by nazmul.3026
For printing all data
用于打印所有数据
print(df)
打印(df)
By Default it will print top 5 records for head.
默认情况下,它将打印头部的前 5 条记录。
print(df.head())
打印(df.head())
If you need 10 rows then you can write this way
如果你需要 10 行,那么你可以这样写
print(df.head(10))
打印(df.head(10))

