combine list to datafrmaep python code example

Example 1: python how to Create Pandas Dataframe from Multiple Lists

# Short answer:
# The simplest approach is to make a dictionary from the lists and then
# to convert the dictionary to a Pandas dataframe.

# Example usage:
import pandas as pd

# Lists you want to convert to a Pandas dataframe
months = ['Jan','Apr','Mar','June']
days = [31, 30, 31, 30]

# Make dictionary, keys will become dataframe column names
intermediate_dictionary = {'Month':months, 'Day':days}

# Convert dictionary to Pandas dataframe
pandas_dataframe = pd.DataFrame(intermediate_dictionary)

print(pandas_dataframe)
	Month	Day
0	Jan		31
1	Apr		30
2	Mar		31
3	June	30

Example 2: how to create a dataframe from two lists in python

# Python 3 to get list of tuples from two lists
data_tuples = list(zip(Month,Days))
data_tuples
[('Jan', 31), ('Apr', 30), ('Mar', 31), ('June', 30)]

>pd.DataFrame(data_tuples, columns=['Month','Day'])
 Month Day
0 Jan 31
1 Apr 30
2 Mar 31
3 June 30