From the course: Complete Guide to Advanced SQL Server

Unlock the full course today

Join today to access over 24,400 courses taught by industry experts.

Add multiple series to a DataFrame

Add multiple series to a DataFrame - SQL Server Tutorial

From the course: Complete Guide to Advanced SQL Server

Add multiple series to a DataFrame

The main difference between a series and a DataFrame is that a DataFrame can hold multiple columns of data. To combine multiple series into a single DataFrame, you're going to need to use the DataFrame constructor. Let's start by creating several variables to hold some text. The first three, A, B, and C, will be set to the values of apple, banana, and cherry, and the second set of three, X, Y, and Z, will be the colors red, yellow, and red again. Now, first, I'm going to collect these scalars and group them into two different series. The first one I'll call fruit. We're going to group them into a pandas series and we'll import the list for A, B, and C. The second series I'll call color and that'll import the list X, Y, and Z. Now, I want to add both of these as two different columns in a single DataFrame. We can do this by constructing the DataFrame from something called a dictionary. A Python dictionary separates groups of keys and values with a colon and is contained within curly…

Contents