1import pandas as pd
2
3data = [['New York Yankees', 'Acevedo Juan', 900000, 'Pitcher'],
4 ['New York Yankees', 'Anderson Jason', 300000, 'Pitcher'],
5 ['New York Yankees', 'Clemens Roger', 10100000, 'Pitcher'],
6 ['New York Yankees', 'Contreras Jose', 5500000, 'Pitcher']]
7
8df = pd.DataFrame.from_records(data)
1# Short answer:
2# The simplest approach is to make a dictionary from the lists and then
3# to convert the dictionary to a Pandas dataframe.
4
5# Example usage:
6import pandas as pd
7
8# Lists you want to convert to a Pandas dataframe
9months = ['Jan','Apr','Mar','June']
10days = [31, 30, 31, 30]
11
12# Make dictionary, keys will become dataframe column names
13intermediate_dictionary = {'Month':months, 'Day':days}
14
15# Convert dictionary to Pandas dataframe
16pandas_dataframe = pd.DataFrame(intermediate_dictionary)
17
18print(pandas_dataframe)
19 Month Day
200 Jan 31
211 Apr 30
222 Mar 31
233 June 30
1# Import pandas library
2import pandas as pd
3
4# initialize list of lists
5data = [['tom', 10], ['nick', 15], ['juli', 14]]
6
7# Create the pandas DataFrame
8df = pd.DataFrame(data, columns = ['Name', 'Age'])
9
10# print dataframe.
11df
12