zoukankan      html  css  js  c++  java
  • 《利用python进行数据挖掘》pivot_table()方法报错

    在MovieLens 1M数据集其中一个例子,使用pivot_table()按性别计算每部电影的平均得分

    1 mean_ratings = data.pivot_table('rating', rows='title', cols='gender', aggfunc='mean')
    2 print mean_ratings[:5]

    报错信息:

    Traceback (most recent call last):
    File "/Users/huanghonglin/PycharmProjects/DataMining/demo2.py", line 26, in <module>
    mean_ratings = data.pivot_table('rating', rows='title', cols='gender', aggfunc='mean')
    TypeError: pivot_table() got an unexpected keyword argument 'rows'

    解决问题:

    将 rows 替换成 index;

    将 cols 替换成 columns。

    1 mean_ratings = data.pivot_table('rating', index='title', columns='gender', aggfunc='mean')
    2 print mean_ratings[:5]

    输出结果

    gender                                        F              M

    title 

    $1,000,000 Duck (1971)         3.375000  2.761905

    'Night Mother (1986)              3.388889  3.352941

    'Til There Was You (1997)       2.675676  2.733333

    'burbs, The (1989)                 2.793478 2.962085

    ...And Justice for All (1979)    3.828571 3.689024

  • 相关阅读:
    kafka的概念
    java的多线程:java安全问题产生的原因与JMM的关系
    java的多线程:线程安全问题
    web自动化之键盘操作
    获取cookie里面的sessionid
    Python连接mysql数据库
    Python 发送Email
    Python日志模块
    openxl模块从excel里面读取数据
    Python读取配置文件
  • 原文地址:https://www.cnblogs.com/S-yesir/p/4807516.html
Copyright © 2011-2022 走看看