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.

Convert a series to a DataFrame

Convert a series to a DataFrame

Before you can pass data out of a Python script back to a SQL Server result set, it first needs to pass through a number of data containers. The process is going to look something like this. A collection of single scalar values are grouped together into a Python list. Then the list can be converted into a pandas series. From there, the series gets converted into a pandas DataFrame. A DataFrame is another pandas construct, like a series, but where a series can only include a single column of values, a DataFrame can contain one or more columns. Finally, the DataFrame can be assigned to the output data set variable and the contents are passed back to a SQL Server result set. Let's take a look at all of the steps in a single script. I'm starting with a couple of scalars A, B, and C that contain text strings. First, I need to put these into a list. That's done with square bracket notation, and each scalar gets separated by commas. Then the list gets converted into a series. You do that…

Contents