python pandas dataframe head()什么都不显示 [英] python pandas dataframe head() displays nothing
问题描述
我是熊猫的新手,但我不知道该怎么做:
I am new to using pandas and I just don't know what to do with this :
我正在使用python.我已经(正确地)安装了蟒蛇.在我的文件中,我只是简单地创建了一个DataFrame(首先通过从read_csv导入它,然后手动重新创建它来确保这不是问题). 当我打印(数据框)时,它会打印:
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:
km | price
0 | 240000 | 3650
[...]
23 | 61789 | 8290
当我执行dataframe.info()时,我得到了这个信息:
When I do dataframe.info() I get this :
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
这是完美的.但是我尝试的任何其他简单功能都显示无".我尝试了dataframe.head(),dataframe ['km'],dataframe [3:6]等.没有错误,但是我的终端上一碗碗什么也没有.
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.
编辑以添加示例代码:
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"]
推荐答案
您必须使用:
print(dataframe.head())
print(dataframe['km'])
print(dataframe[3:6])
没有打印语句,python只是选择数据,而不对它做任何事情.
Without the print statement python is just selecting the data but not doing anything with it.
这篇关于python pandas dataframe head()什么都不显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!