python的head函数输不出数据,python pandas dataframe head()什么都不显示

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

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

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

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.

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"]

解决方案

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.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Pandas 是一个强大的数据分析工具,提供了很多常用的函数来处理数据,下面是一些常用的函数及其用法: 1. read_csv():读取 CSV 文件并返回一个 DataFrame 对象。 2. head():返回 DataFrame 的前几行数据,默认为前 5 行。 3. tail():返回 DataFrame 的后几行数据,默认为后 5 行。 4. info():返回 DataFrame 的基本信息,包括每列的数据类型、非空数量等。 5. describe():返回 DataFrame 的基本统计信息,包括计数、均、标准差、最小、最大等。 6. shape:返回 DataFrame 的行数和列数。 7. columns:返回 DataFrame 的列名。 8. index:返回 DataFrame 的行索引。 9. loc[]:根据行标签和列标签访问 DataFrame 中的元素。 10. iloc[]:根据行索引和列索引访问 DataFrame 中的元素。 11. dropna():删除 DataFrame 中的缺失。 12. fillna():用指定的或方法填充 DataFrame 中的缺失。 13. groupby():按照指定的列对 DataFrame 进行分组。 14. apply():对 DataFrame 的每一列应用指定的函数。 15. pivot_table():根据指定的列计算 DataFrame 的透视表。 16. merge():将两个 DataFrame 按照指定的列进行合并。 17. sort_values():按照指定的列对 DataFrame 进行排序。 18. drop_duplicates():去除 DataFrame 中的重复行。 19. value_counts():统计 DataFrame 中每个元素出现的次数。 20. isnull():判断 DataFrame 中的元素是否为空。 这些函数覆盖了 Pandas 中的很多常用操作,掌握它们对于数据分析和处理非常有帮助。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值