码迷,mamicode.com
首页 > 编程语言 > 详细

Python for Data Science - Creating statistical charts

时间:2021-01-25 11:18:24      阅读:0      评论:0      收藏:0      [点我收藏+]

标签:lang   data   learn   graph   and   isp   frame   box   http   

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‘)

技术图片

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‘)

技术图片

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

技术图片

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

技术图片

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

技术图片

Creating box plots

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

技术图片

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‘)

技术图片

Python for Data Science - Creating statistical charts

标签:lang   data   learn   graph   and   isp   frame   box   http   

原文地址:https://www.cnblogs.com/keepmoving1113/p/14317219.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!