python - Pandas 描述()不显示

标签 python pandas machine-learning

我正在学习有关机器学习的 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

希望这对您有所帮助!

关于python - Pandas 描述()不显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50169437/

相关文章:

python重新匹配 "space at the end of string"

python - 用大数组中的零替换空值或缺失值

Python 邮件在 Outlook 主题行中放置不明空间

python - 根据来自不同数据框的两列条件乘以列?

python - Pandas - 使用多个值填充 NaN

python - 将 Pandas 中的字符串数字列转换为 float

python - 将 Pandas 数据框附加到 Google 电子表格

machine-learning - 使用 tensorflow 预测车祸

python - 在 svm 中预测多类

python - 如何评估 scikit 学习 LogisticRegression 的成本函数?