Skip to content
Writing Efficient Python Code
  • AI Chat
  • Code
  • Report
  • Writing Efficient Python Code

    Run the hidden code cell below to import the data used in this course.

    # Importing pandas
    import pandas as pd
    
    # Reading in the data
    baseball = pd.read_csv("datasets/baseball.csv")

    Take Notes

    Add notes about the concepts you've learned and code cells with code you want to keep.

    Unpacking in Python using - (*)

    # Create a range object that goes from 0 to 5
    nums = range(0,5)
    print(type(nums))
    
    # Convert nums to a list
    nums_list = list(nums)
    print(nums_list)
    
    # Create a new list of odd numbers from 1 to 11 by unpacking a range object
    nums_list2 = [*range(1,11,2)]
    print(nums_list2)

    The power of NumPy arrays over python list

    A numpy array contains homogeneous data types (which reduces memory consumption) and provides the ability to apply operations on all elements through broadcasting.