DataFrames with Python

Free Video Tutorial and Guide

In this video, we're going to look at how to create Databases in multiple ways using Python.

Video Transcription

Hi, my name is Art, and I teach Python at Noble Desktop. In this video, I'm going to show you how you can create a data frame from a bunch of lists. First, let's import Pandas as "pd".

Python for Data Science Bootcamp: Live & Hands-on, In NYC or Online, Learn From Experts, Free Retake, Small Class Sizes,  1-on-1 Bonus Training. Named a Top Bootcamp by Forbes, Fortune, & Time Out. Noble Desktop. Learn More.

Suppose we have a couple of lists. A list is a very popular Python container, and most of the time when you gather information (maybe you use web scraping techniques to gather information) you would use a list, and then you want to take those lists and convert them into a data frame.

Suppose we have a list of cities: New York, Chicago, Orlando, and Boston. Then we have a list of states: New York, Illinois, Florida, and Massachusetts. Then we have a population list (in millions): 10.5, 4.5, 1.6, and 2.5.

We have three Python lists. Now we want to convert and create the data frame. To do this, we might want to create one more list called labels. In this list, I want to place labels for my future columns: City, State, and Population.

Now we can compose them as another list called list_data. List_data is a list of lists. Now we can use the zip function. Zip always returns an object, so we can unpack this list using the list function.

We now have a list of tuples, and all we have to do is convert this to a dictionary. We can assign it the variable name data, and it will be a dictionary with keys: City, State, and Population.

Now, all we have to do is create a variable name for our future data frame (pd_data_frame) and pass the dictionary. Now you have this data frame with the index, columns, and all the values.

How to Learn Python

Master Python with hands-on training. Python is a popular object-oriented programming language used for data science, machine learning, and web development. 

Yelp Facebook LinkedIn YouTube Twitter Instagram