• 建强 置顶
    2019-08-18
    思考题1:对车祸数据成对关系的的探索,程序代码如下:

    #车祸数据分析
    import matplotlib.pyplot as plt
    import seaborn as sns
    import pandas as pd
    # 数据准备
    crashes = sns.load_dataset('car_crashes')
    crashes_data = pd.DataFrame(crashes)

    # 用 Seaborn 画成对关系
    sns.pairplot(crashes)
    plt.show()

    思考题2:模拟企业隐患数据分析,代码如下:

    import pandas as pd
    import matplotlib.pyplot as plt
    import seaborn as sns
    import numpy as np

    #定义生成隐患数量函数
    def GenerateHDNum(hdtimes):
        #hdtimes表示要生成多少隐患数量
        HD_NumList = list(pd.Series(np.random.rand(hdtimes)))
        return [int(x * 100) for x in HD_NumList]

    #数据准备函数
    def MakeData():

        #创建以月份为单位的时间索引
        dti = pd.date_range(start='2017-01-01', end='2018-12-31', freq='M')
        monthlist = [str(x * 100 + y) for x,y in zip(dti.year,dti.month)]
        
        hdtimes = len(monthlist)
        #生成各种隐患数量
        NormalHD = GenerateHDNum(hdtimes)
        ImportHD = GenerateHDNum(hdtimes)
        HDNum = { 'Normal': NormalHD
                 ,'Import': ImportHD}

        HD_Frame = pd.DataFrame(data = HDNum, index=monthlist)

        print(HD_Frame)
        return HD_Frame

    def AnalyData(HDSet,AnalyType='0'):

        #AnalyType取值:1:成对关系图;2:散点图;3:核密度图;4:Hexbin图

        #成对关系图
        if AnalyType == '1':
            sns.pairplot(HDSet)

        #散点图
        if AnalyType == '2':
            sns.jointplot(x='Normal', y='Import', data=HDSet, kind='scatter')

        #核密度图
        if AnalyType == '3':
            sns.jointplot(x='Normal', y='Import', data=HDSet, kind='kde')

        #Hexbin图
        if AnalyType == '4':
            sns.jointplot(x='Normal', y='Import', data=HDSet, kind='hex')
        
        plt.show()

    def ShowMenu():
        print('='*20)
        print('1.显示成对关系图')
        print('2.显示散点图')
        print('3.显示核密度图')
        print('4.显示Hexbin图')
        print('R.换一批数据')
        print('0.退出')
        print('='*20)
        return input('请输入命令:')

    def main():

        HDSet = MakeData()
        while True:
            command = ShowMenu()

            if command == '0':
                break
            elif command == 'R':
                HDSet = MakeData()
            else:
                AnalyData(HDSet, command)

    main()
    展开

    作者回复: 建强同学很不错的作业分享,大家都可以看下

    
    
  • 佳佳的爸
    2019-01-17
    建议所有的示例代码加上完整的引用(完整的import语句),谢谢!
     1
     30
  • 数据化分析
    2019-01-16
    # -*- coding: utf-8 -*-
    # 作者:数据化分析
    # 微信公众号:isjhfx
    # 版本:1.0

    import matplotlib.pyplot as plt
    import seaborn as sns

    # 解决seaborn数据集导入报错的问题
    import ssl
    ssl._create_default_https_context = ssl._create_unverified_context

    # 数据准备
    data = sns.load_dataset('car_crashes')
    print(data.head(10))

    # 用 seaborn 探索成对关系
    sns.pairplot(data)

    # 用 seaborn 画散点图
    sns.jointplot(x='total', y='speeding', data=data, kind='scatter')

    # 用 seaborn 画核密度图
    sns.jointplot(x='total', y='speeding', data=data, kind='kde')

    # 用 seaborn 画 Hexbin 图
    sns.jointplot(x='total', y='speeding', data=data, kind='hex')

    plt.show()
    展开
    
     9
  • sxpujs
    2019-04-21
    在 Mac 下设置中文字体,可以使用以下路径:
    # 设置中文字体
    font = FontProperties(fname="/System/Library/Fonts/STHeiti Medium.ttc", size=14)

    作者回复: 很好的分享

    
     6
  • Andre
    2019-06-05
    我的想法是把老师的几种操作,自己做一遍然后发到github和自己的知乎专栏上面
    
     2
  • jsw
    2019-01-17
    我的数据和程序都在服务器上,如何可以生成html在web上展示?
     1
     2
  • 跳跳
    2019-01-16
    第一题:seaborn car_crashes成对关系探索
    iris=sns.load_dataset("car_crashes")
    sns.pairplot(iris)
    plt.show()
    第二题:由第一题可以看出酒精和速度由类似线性关系,因此做酒精和速度二元变量的分布图
    iris=sns.load_dataset("car_crashes")
    print(iris.head(10))
    sns.jointplot(x='alcohol',y='speeding',data=iris,kind='scatter')
    sns.jointplot(x='alcohol',y='speeding',data=iris,kind='kde')
    sns.jointplot(x='alcohol',y='speeding',data=iris,kind='hex')
    碎碎念一下:为啥留言不支持图片?难受
    展开

    作者回复: 哈哈 支持图片这个需要技术来做

    
     2
  • 阿敦教授
    2019-06-03
    老师您好,在用sns.load_dataset()时,不管load哪个在线数据集,都报错 urllib.error.URLError: <urlopen error [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1056)>。请问怎么解决呀?谢谢老师
     1
     1
  • 周飞
    2019-02-27
    折线图的demo 中 如果运行出现如下的错误 : AttributeError: module 'seaborn' has no attribute 'lineplot'. 请看这里 https://stackoverflow.com/questions/51846948/seaborn-lineplot-module-object-has-no-attribute-lineplot 。 解决方案是 : conda install -c anaconda seaborn=0.9.0
    
     1
  • 周飞
    2019-02-27
    macOS的用户如果不能显示,请看这里:https://matplotlib.org/faq/osx_framework.html#conda
    conda install python.app 然后 用pythonw 来运行脚步,此时可能会报错: Intel MKL FATAL ERROR: Cannot load libmkl_intel_thread.dylib. , 然后看这里 https://blog.csdn.net/u010900574/article/details/53413937 运行 conda install -f numpy 和 conda install mkl 。然后在用pythonw 来运行脚本就可以了。
    
     1
  • 毛毛🐛虫🌻
    2019-01-18
    热力图那个是颜色越浅,值越大么?

    作者回复: 对 右侧有坐标对照

     1
     1
  • 拉我吃
    2019-01-17
    # coding:utf-8
    import matplotlib.pyplot as plt
    import seaborn as sns

    # Data Prep
    car_crashes = sns.load_dataset('car_crashes')
    sns.pairplot(car_crashes)
    plt.show()

    # plot with seaborn (scatter, kde, hex)
    sns.jointplot(x='alcohol', y='speeding', data=car_crashes, kind='scatter')
    sns.jointplot(x='alcohol', y='speeding', data=car_crashes, kind='kde')
    sns.jointplot(x='alcohol', y='speeding', data=car_crashes, kind='hex')
    plt.show()

    二元关系选了喝酒和超速的对比,基本上在大部分区间下是线性关系,就是喝得多速度快:)
    展开

    作者回复: 加油~

    
     1
  • 舒成
    2019-01-16
    python在慢慢追赶R,我的R语言分析水平停止了,python水平在往上涨,现在的状态是,有老师的课就学课,没有就看《精益数据分析》。

    作者回复: 嗯嗯 慢慢来 坚持就有收获

     1
     1
  • GS
    2019-11-23
    奉上我的笔记 https://github.com/leledada/jupyter/blob/master/matplotlibDemo.ipynb

    作者回复: 赞GS同学

    
    
  • GS
    2019-11-18
    遇到个问题:'module' object has no attribute 'lineplot'.
    https://stackoverflow.com/questions/51846948/seaborn-lineplot-module-object-has-no-attribute-lineplot
    解决方案:
    pip install seaborn==0.9.0

    作者回复: 嗯 多谢分享

    
    
  • 陈云飞
    2019-07-22
    可以把三维图、曲面图加上,这两个非常重要,用的也比较多

    作者回复: 很好的建议

    
    
  • 华夏
    2019-07-06
    load在线数据集的时候报错 urllib.error.URLError: <urlopen error [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1056)>
    如果是mac的话,可以打开终端,输入 cd "/Applications/Python 3.7/" (你是Python3.几就输入3.几)
    然后 sudo "./Install Certificates.command" 就可以解决问题了。
    下面贴一个解决问题的链接 https://stackoverflow.com/questions/27835619/urllib-and-ssl-certificate-verify-failed-error/42334357#42334357
    展开
    
    
  • David
    2019-07-02
    import matplotlib.pyplot as plt
    import seaborn as sns

    # 数据准备
    # x = ['Cat1', 'Cat2', 'Cat3', 'Cat4', 'Cat5']
    x = [1, 2, 3, 4, 5]
    y = [5, 4, 8, 12, 7]
    # 用 Matplotlib 画条形图
    plt.bar(x, y)
    plt.show()
    # 用 Seaborn 画条形图
    sns.barplot(x, y)
    plt.show()

    请教,我的环境x轴只能是float类型,这是什么原因呢?
    展开
    
    
  • 董大琳儿
    2019-06-23
    import matplotlib.pyplot as plt
    import seaborn as sns
    # 数据准备
    iris = sns.load_dataset('iris')
    # 用 Seaborn 画成对关系
    sns.pairplot(iris)
    plt.show()
    展开

    作者回复: Good Job

    
    
  • 滢
    2019-04-15
    语言Python3.6, 环境IDLE
    >>> car_crashes = sns.load_dataset('car_crashes')
    第一个问题:
    >>> sns.pairplot(car_crashes)
    <seaborn.axisgrid.PairGrid object at 0x125a9cdd8>
    第二个问题:查看获取到的数据维度,针对车祸数与速度画二元变量分布图,以及针对车祸数与酒精含量画二元变量分布图
    >>> sns.jointplot(x='total',y='speeding',data=car_crashes,kind='scatter')
    <seaborn.axisgrid.JointGrid object at 0x1259d7d68>
    >>> sns.jointplot(x='total',y='speeding',data=car_crashes,kind='kde')
    <seaborn.axisgrid.JointGrid object at 0x129fe9ba8>
    >>> sns.jointplot(x='total',y='speeding',data=car_crashes,kind='hex')
    <seaborn.axisgrid.JointGrid object at 0x12ff26eb8>
    >>> sns.jointplot(x='total',y='alcohol',data=car_crashes,kind='scatter')
    <seaborn.axisgrid.JointGrid object at 0x131b19550>
    >>> sns.jointplot(x='total',y='alcohol',data=car_crashes,kind='kde')
    <seaborn.axisgrid.JointGrid object at 0x129f5a630>
    >>> sns.jointplot(x='total',y='alcohol',data=car_crashes,kind='hex')
    <seaborn.axisgrid.JointGrid object at 0x12605c630>
    >>> plt.show()

    最后执行一次plt.show() 所创建的图片都会显示出来
    展开

    作者回复: Good Job

    
    
我们在线,来聊聊吧