Take multiple lists into dataframe
I think you're almost there, try removing the extra square brackets around the lst
's (Also you don't need to specify the column names when you're creating a dataframe from a dict like this):
import pandas as pdlst1 = range(100)lst2 = range(100)lst3 = range(100)percentile_list = pd.DataFrame( {'lst1Title': lst1, 'lst2Title': lst2, 'lst3Title': lst3 })percentile_list lst1Title lst2Title lst3Title0 0 0 01 1 1 12 2 2 23 3 3 34 4 4 45 5 5 56 6 6 6...
If you need a more performant solution you can use np.column_stack
rather than zip
as in your first attempt, this has around a 2x speedup on the example here, however comes at bit of a cost of readability in my opinion:
import numpy as nppercentile_list = pd.DataFrame(np.column_stack([lst1, lst2, lst3]), columns=['lst1Title', 'lst2Title', 'lst3Title'])
Adding to Aditya Guru's answer here. There is no need of using map. You can do it simply by:
pd.DataFrame(list(zip(lst1, lst2, lst3)))
This will set the column's names as 0,1,2. To set your own column names, you can pass the keyword argument columns
to the method above.
pd.DataFrame(list(zip(lst1, lst2, lst3)), columns=['lst1_title','lst2_title', 'lst3_title'])