Search icon CANCEL
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Big Data Analysis with Python

You're reading from   Big Data Analysis with Python Combine Spark and Python to unlock the powers of parallel computing and machine learning

Arrow left icon
Product type Paperback
Published in Apr 2019
Publisher Packt
ISBN-13 9781789955286
Length 276 pages
Edition 1st Edition
Languages
Tools
Concepts
Arrow right icon
Authors (3):
Arrow left icon
Ivan Marin Ivan Marin
Author Profile Icon Ivan Marin
Ivan Marin
Sarang VK Sarang VK
Author Profile Icon Sarang VK
Sarang VK
Ankit Shukla Ankit Shukla
Author Profile Icon Ankit Shukla
Ankit Shukla
Arrow right icon
View More author details
Toc

Table of Contents (11) Chapters Close

Big Data Analysis with Python
Preface
1. The Python Data Science Stack 2. Statistical Visualizations FREE CHAPTER 3. Working with Big Data Frameworks 4. Diving Deeper with Spark 5. Handling Missing Values and Correlation Analysis 6. Exploratory Data Analysis 7. Reproducibility in Big Data Analysis 8. Creating a Full Analysis Report Appendix

Chapter 08: Creating a Full Analysis Report


Activity 15: Generating Visualization Using Plotly

  1. Import all the required libraries and packages into the Jupyter notebook. Make sure to read the data from bank.csv into the Spark DataFrame.

  2. Import the libraries for Plotly, as illustrated here:

    import plotly.graph_objs as go
    from plotly.plotly import iplot
    import plotly as py
  3. Now, for visualization in Plotly, we need to initiate an offline session. Use the following command (requires version >= 1.9.0):

    from plotly import __version__
    from plotly.offline import download_plotlyjs, init_notebook_mode, plot, iplot
    print(__version__)
  4. Now Plotly is initiated offline. Use the following command to start a Plotly notebook:

    import plotly.plotly as py
    import plotly.graph_objs as go
    
    init_notebook_mode(connected=True)

    After starting the Plotly notebook, we can use Plotly to generate many types of graphs, such as a bar graph, a boxplot, or a scatter plot, and convert the entire output into a user interface or an app that is supported by Python's Flask framework.

  5. Now, plot each graph using Plotly:

    Bar graph:

    df = pd.read_csv('bank.csv', sep=';')
    data = [go.Bar(x=df.y,
                y=df.balance)]
    
    py.iplot(data)

    The bar graph is as follows:

    Figure 8.18: Bar graph

    Scatter plot:

    py.iplot([go.Histogram2dContour(x=df.balance, y=df.age, contours=dict(coloring='heatmap')),
           go.Scatter(x=df.balance, y=df.age, mode='markers', marker=dict(color='red', size=8, opacity=0.3))], show_link=False)

    The scatter plot is as follows:

    Figure 8.19: Scatter plot

    Boxplot:

    plot1 = go.Box(
        y=df.age,
        name = 'age of the customers',
        marker = dict(
            color = 'rgb(12, 12, 140)',
        )
    )
    py.iplot([plot1])

    The boxplot is as follows:

    Figure 8.20: Boxplot

lock icon The rest of the chapter is locked
arrow left Previous Section
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at R$50/month. Cancel anytime