I am trying to convert a list of lists which looks like the following into a Pandas Dataframe
[['New York Yankees ', '"Acevedo Juan" ', 900000, ' Pitcher\n'],
['New York Yankees ', '"Anderson Jason"', 300000, ' Pitcher\n'],
['New York Yankees ', '"Clemens Roger" ', 10100000, ' Pitcher\n'],
['New York Yankees ', '"Contreras Jose"', 5500000, ' Pitcher\n']]
I am basically trying to convert each item in the array into a pandas data frame which has four columns. What would be the best approach to this as pd.Dataframe does not quite give me what I am looking for.
DataFrame.from_records(data, columns=['Team', 'Player', 'whatever-stat-is-that', 'position'])
– Juan Ignacio Gil Jan 11 '18 at 10:14DataFrame["Team"]
must refer to the first item of each sublist (i.e.data[i][0]
) andDataFrame["Position"]
to refer to the last item of each sublist (i.e.data[i][-1]
)? – Ivo Jan 17 '19 at 15:20columns
parameter of DataFrame.from_records. – Emre Jan 17 '19 at 21:27