python - 尝试使用 numpy 在 Python 中创建自定义函数
问题描述
我正在尝试创建一个自定义函数来输出我的数据框的详细信息。我在我的 jupyter 笔记本上运行以下代码,但它只是运行而没有显示任何输出。
def details(mydf,n):
mydf.shape
mydf.dtypes
mydf.head(n)
mydf.tail(n)
return None
mydf=pd.read_csv("House.Price.csv",low_memory=False)
details(mydf,5)
解决方案
要显示jupyter
使用中的数据功能display(<arg>)
,如下所示:
def details(mydf,n):
display(mydf.shape)
display(mydf.dtypes)
display(mydf.head(n))
display(mydf.tail(n))
编辑
display()
函数还可以配置您要输出多少行或列。
pd.set_option('display.max_rows', 500)
pd.set_option('display.max_rows', None) // for all
pd.set_option('display.max_columns', 500)
你正在做的是调用一个返回的函数,None
因此没有输出,因为默认情况下jupyter
只打印块的最后一行返回的值。
推荐阅读
- c# - LINQ 按内部列表的属性对外部列表进行排序
- python - Numpy:如何将 (N,N) 和 (N,N,M,M) numpy 数组相乘?
- r - 如何在 r 中创建姓名的 Qrcode 列表
- python - 用于实现 Django SAML2 身份验证的 Xmlsec 库
- android - 未找到加载的动态功能的主要活动类
- sql - 无法在我的 Bug_Project 表中插入一行
- c# - 如何在域驱动设计中指定用户限制?
- ios - 删除 use_frameworks 然后出现错误“无法为“xxx”加载底层模块”
- c# - 从 C# 中的 DataTable 中删除 DataRow
- java - 将 Gradle 中的变量传递给 Android Studio 中的 bash 文件