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 as pd
2import pandas as pd
3
4# list of strings
5lst = ['Geeks', 'For', 'Geeks', 'is',
6 'portal', 'for', 'Geeks']
7
8# Calling DataFrame constructor on list
9df = pd.DataFrame(lst)
10df
1In [8]: data = pd.DataFrame({'x': x, 'sin(x)': y})
2In [9]: data
3Out[9]:
4 x sin(x)
50 0.000000 0.000000e+00
61 0.349066 3.420201e-01
72 0.698132 6.427876e-01
83 1.047198 8.660254e-01
94 1.396263 9.848078e-01
105 1.745329 9.848078e-01
116 2.094395 8.660254e-01
127 2.443461 6.427876e-01
138 2.792527 3.420201e-01
149 3.141593 1.224647e-16
15
16[10 rows x 2 columns]