What is dataframe in Python

Create a pandas dataframe from a list

  1. How-To's
  2. Python Pandas How-To's
  3. Create a pandas dataframe from a list

Created: December-26, 2020

  1. Use single list to create Pandas DataFrame
  2. Use multiple lists to create a panda DataFrame
  3. Use multidimensional list to generate Panda's DataFrame

Pandas allows us to create a Pandas DataFrame from a list using the method. We can do this with a single list, multiple lists, and multidimensional lists.

Use single list to create Pandas DataFrame

This is the simplest case that generates a data frame from a single list. We just pass the list to and the result is a single column data frame.

Example:

Output:

Use multiple lists to create a panda DataFrame

To create a Pandas DataFrame from more than one list, we have to use the function. The function returns an object of the type that pairs the elements in the first position with each other, in the second position with each other, and so on. Each list acts as a different column.

Example:

Output:

Use multidimensional list to generate Panda's DataFrame

A list that contains another list is called a multidimensional list. In this case, each list nested within the main list acts as a line for the data frame. The following example shows how to do this:

Output:

Related Article - Pandas DataFrame

  • Show all columns of a panda DataFrame
  • How to add a new column to an existing DataFrame with default value in pandas