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

    Histograms

    from:https://campus.datacamp.com/courses/intermediate-python-for-data-science/matplotlib?ex=7

    • Build a histogram (1)

    life_exp, the list containing data on the life expectancy for different countries in 2007, is available in your Python shell.

    To see how life expectancy in different countries is distributed, let's create a histogram of life_exp.

    # import matplotlib.pyplot

    import matplotlib.pyplot as plt

    # Create histogram of life_exp data. Do not specify the number of bins; Python will set the number of bins to 10 by default for you.

    plt.hist(life_exp)

    # Display histogram
    plt.show()

    • Build a histogram (2): bins

    To control the number of bins to divide your data in, you can set the bins argument.

    # Build histogram with 5 bins
    plt.hist(life_exp, bins = 5)

    # Show and clean up plot
    plt.show()
    plt.clf()

    # Build histogram with 20 bins
    plt.hist(life_exp,bins = 20)

    # Show and clean up again
    plt.show()
    plt.clf()

    • Build a histogram (3): compare

    Let's do a similar comparison. life_exp contains life expectancy data for different countries in 2007. You also have access to a second list now, life_exp1950, containing similar data for 1950. Can you make a histogram for both datasets?

    # Histogram of life_exp, 15 bins
    import matplotlib.pyplot as plt
    plt.hist(life_exp, bins = 15)

    # Show and clear plot
    plt.show()
    plt.clf()

    # Histogram of life_exp1950, 15 bins
    plt.hist(life_exp1950, bins = 15)

    # Show and clear plot again
    plt.show()
    plt.clf()

    • Choose the right plot (1)

    You're a professor teaching Data Science with Python, and you want to visually assess if the grades on your exam follow a particular distribution. Which plot do you use?

    ->Histogram

    • Choose the right plot (2)

    You're a professor in Data Analytics with Python, and you want to visually assess if longer answers on exam questions lead to higher grades. Which plot do you use?

    ->Scatter plot

  • 相关阅读:
    lambda表达式
    PAT 1071. Speech Patterns
    PAT 1070. Mooncake
    1069. The Black Hole of Numbers
    PAT 1068. Find More Coins
    背包问题(动态规划)
    PAT 1067. Sort with Swap(0,*)
    PAT 1066. Root of AVL Tree
    PAT 1065. A+B and C
    PAT 1064. Complete Binary Search Tree
  • 原文地址:https://www.cnblogs.com/keepSmile/p/7797964.html
Copyright © 2011-2022 走看看