Skip to content

Latest commit

 

History

History
96 lines (72 loc) · 2.03 KB

Python_Create_dataframe_from_lists.md

File metadata and controls

96 lines (72 loc) · 2.03 KB



Template request | Bug report | Generate Data Product

Tags: #python #list #dataframe #snippet #pandas #operations

Author: Florent Ravenel

Description: This notebook provides instructions on how to use Python to create a dataframe from lists.

Input

Import libraries

import pandas as pd

Variables

# Setup your columns name
col_key = "KEYS"
col_value = "VALUE"

Lists

keys = [
    1995,
    1996,
    1997,
    1998,
    1999,
    2000,
    2001,
    2002,
    2003,
    2004,
    2005,
    2006,
    2007,
    2008,
    2009,
    2010,
    2011,
    2012,
]
value = [
    219,
    146,
    112,
    127,
    124,
    180,
    236,
    207,
    236,
    263,
    350,
    430,
    474,
    526,
    488,
    537,
    500,
    439,
]

Model

Create zip iterator

# Call zip(iter1, iter2) with one list as iter1 and another list as iter2 to create a zip iterator containing pairs of elements from the two lists.
zip_iterators = zip(keys, value)

Output

Create dataframe

df = pd.DataFrame(zip_iterators, columns=[col_key, col_value])
df