python pandas dataframe head() 什么都不显示

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/33483707/
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-14 00:08:58  来源:igfitidea点击:

python pandas dataframe head() displays nothing

pythonpandasdataframeanaconda

提问by Lauref

I am new to using pandas and I just don't know what to do with this :

我是使用Pandas的新手,我只是不知道该怎么做:

I am using python. I have (properly) installed anaconda. In my file I simply create a DataFrame (first by importing it from read_csv, then recreating it by hand to make sure that was not the problem). When I do print (dataframe) it prints:

我正在使用蟒蛇。我已经(正确)安装了 anaconda。在我的文件中,我只是创建了一个 DataFrame(首先从 read_csv 导入它,然后手动重新创建它以确保这不是问题)。当我打印(数据框)时,它会打印:

        km |  price
0  | 240000 |  3650

[...]

23  | 61789 |  8290

When I do dataframe.info() I get this :

当我做 dataframe.info() 我得到这个:

class 'pandas.core.frame.DataFrame'

Int64Index: 24 entries, 0 to 23

Data columns (total 2 columns):

km       24 non-null int64

price    24 non-null int64

dtypes: int64(2)

memory usage: 576.0 bytes

Which is perfect. But any other simple function I try just displays NOTHING. I tried dataframe.head(), dataframe['km'], dataframe[3:6], etc. No errors, just a big bowl of nothing on my terminal.

这是完美的。但是我尝试的任何其他简单功能都没有显示任何内容。我尝试了 dataframe.head()、dataframe['km']、dataframe[3:6] 等。没有错误,我的终端上只是一大碗空空如也。

Edit to add example code:

编辑以添加示例代码:

import pandas as pd 
import numpy as np 
import matplotlib.pyplot as plt 
pd.set_option('max_columns', 50) 
#df=pd.read_csv('data.csv') 
data = {'km': [240000, 139800, 150500, 185530, 176000, 114800, 166800, 89000, 144500, 84000, 82029, 63060, 74000, 97500, 67000, 76025, 48235, 93000, 60949, 65674, 54000, 68500, 22899, 61789], 'price': [3650, 3800, 4400, 4450, 5250, 5350, 5800, 5990, 5999, 6200, 6390, 6390, 6600, 6800, 6800, 6900, 6900, 6990, 7490, 7555, 7990, 7990, 7990, 8290]} 
df = pd.DataFrame(data, columns=['km', 'price']) 
print (df) 
df.info() 
df[2:5] 
df["km"] 

回答by Ryan

You have to use:

你必须使用:

print(dataframe.head())
print(dataframe['km'])
print(dataframe[3:6])

Without the print statement python is just selecting the data but not doing anything with it.

没有打印语句,python 只是选择数据,而不是对它做任何事情。

回答by Puikit Leung

You may expect this would show some row after seeing how other does. But this only appear only in terminal environment. Just like the above answer, you need an print() to show row while you are using ide

在看到其他人的表现后,您可能会期望这会显示一些行。但是这只出现在终端环境中。就像上面的答案一样,您在使用ide时需要一个 print() 来显示行