Skip to main content
 首页 » 编程设计

python之Pandas 描述()不显示

2025年05月04日16linjiqin

我正在学习有关机器学习的 Google 类(class),并试图让它在 Atom 上运行,而不是简单地使用 colab 版本。模型训练和其他事情进展顺利,但我在使用 describe() 函数时遇到问题。我已经查阅了文档,但仍然无法显示摘要。只有当我在命令行上尝试交互式 python 时,它才起作用。我的代码的相关部分如下。感谢您的帮助。

import math 
 
from IPython import display 
from matplotlib import cm 
from matplotlib import gridspec 
from matplotlib import pyplot as plt 
import numpy as np 
import pandas as pd 
from sklearn import metrics 
import tensorflow as tf 
from tensorflow.python.data import Dataset 
 
tf.logging.set_verbosity(tf.logging.ERROR) 
pd.options.display.max_rows = 10 
pd.options.display.float_format = '{:.lf}'.format 
 
# Load data set 
california_housing_dataframe = pd.read_csv("https://storage.googleapis.com/mledu-datasets/california_housing_train.csv", sep=",") 
 
...... 
 
# Split the data set into training sets of the first 12000/17000 examples, 
training_examples = preprocess_features(california_housing_dataframe.head(12000)) 
training_targets = preprocess_targets(california_housing_dataframe.head(12000)) 
 
# and validation sets of the last 5000/17000 examples. 
validation_examples = preprocess_features(california_housing_dataframe.tail(5000)) 
validation_targets = preprocess_targets(california_housing_dataframe.tail(5000)) 
 
# Double-check that the splitting is correct. (NOT WORKING YET) 
print("Training examples summary:") 
training_examples.describe() 

运行代码后,我的终端简单地忽略带有 describe() 的行并打印出来

Training examples summary:  
Validation examples summary:  
Training targets summary:  
Validation targets summary: 

然后对模型进行训练。

请您参考如下方法:

我也在学习 Google 的 ML 类(class),遇到了同样的问题,即 describe 函数没有打印到我的输出窗口。对我有用的是将 describe() 包装在 print() 函数中,如下所示。

print(california_housing_dataframe.describe())

这在我的输出窗口中生成了描述性统计数据。

免责声明:我正在从 Sublime 而不是 Atom 运行我的 python 程序,并且我正在使用下面的包:

  • 崇高文本 3
  • Pandas 0.23.0
  • tensorflow-GPU 1.8.0
  • CUDA 9.0.176.2
  • cudnn 7.1

希望这对您有所帮助!