zoukankan      html  css  js  c++  java
  • Python for Data Science

    Chapter 7 - Collaborative Analytics with Plotly

    Segment 2 - Creating statistical charts

    Setting up to use Plotly within Jupyter

    import numpy as np
    import pandas as pd
    
    import cufflinks as cf
    
    import chart_studio.plotly as py
    import chart_studio.tools as tls
    import plotly.graph_objs as go
    
    import sklearn
    from sklearn.preprocessing import StandardScaler
    
    tls.set_credentials_file(username='xxxx', api_key='Lx0brxxxxxkKpxYxxxx')
    

    Creating histograms

    Make a histogram from a pandas Series object

    address = '~/Data/mtcars.csv'
    
    cars = pd.read_csv(address)
    cars.columns = ['car_names','mpg','cyl','disp', 'hp', 'drat', 'wt', 'qsec', 'vs', 'am', 'gear', 'carb']
    
    mpg = cars.mpg
    
    mpg.iplot(kind='histogram', filename='simple-histogram-chart')
    

    image-20210123122627948

    cars_subset = cars[['mpg','disp','hp']]
    
    cars_data_std = StandardScaler().fit_transform(cars_subset)
    
    cars_select = pd.DataFrame(cars_data_std)
    cars_select.columns = ['mpg','disp','hp']
    
    cars_select.iplot(kind='histogram', filename = 'multiple-histogram-chart')
    

    image-20210123122645231

    cars_select.iplot(kind='histogram', subplots=True, filename = 'subplot-histograms')
    

    image-20210123122705881

    cars_select.iplot(kind='histogram', subplots=True, shape=(3,1), filename = 'subplot-histograms')
    

    image-20210123122731055

    cars_select.iplot(kind='histogram', subplots=True, shape=(1,3), filename = 'subplot-histograms')
    

    image-20210123122756956

    Creating box plots

    cars_select.iplot(kind='box',filename = 'box-plots')
    

    image-20210123122815112

    Creating scatter plots

    fig = {'data':[{'x':cars_select.mpg, 'y':cars_select.disp,'mode':'markers','name':'mpg'},
                  {'x':cars_select.hp,'y':cars_select.disp,'mode':'markers','name':'hp'}],
          'layout':{'xaxis':{'title':''},'yaxis':{'title':'Standardized Dispplacement'}}}
    py.iplot(fig, filename='grouped-scatter-plot')
    

    image-20210123122826389

  • 相关阅读:
    vba --barcode9.0 生成 code39
    利用JS 阻止表单提交
    VS2012变化的快捷键
    鼠标右击禁用
    计算机算法常用术语中英对照
    GrideView(三)---编辑功能实现
    GrideView(二)---删除功能
    GridView认识(一)
    微软 自带 AJAX 拓展
    C#日期函数使用大全
  • 原文地址:https://www.cnblogs.com/keepmoving1113/p/14317219.html
Copyright © 2011-2022 走看看