Basically, I have 2 lists in python
list1 = ['Archaeology', 'Astronomy', 'Biology', 'Botany'] list2 = ['soccer', 'basketball', 'tennis', 'baseball', 'golf', 'running', 'volleyball']
And now, I want to create a DataFrame in Pandas that looks like this :
How do I go about this task ?
You can simply use the
pandas.DataFrame constructor. You can’t construct it as columns directly as the number of elements is unequal (this wouldn’t work), but you can make it as rows and transpose:
pd.DataFrame([list1, list2], index=['academics', 'sports']).T
academics sports 0 Archaeology soccer 1 Astronomy basketball 2 Biology tennis 3 Botany baseball 4 None golf 5 None running 6 None volleyball