Getting A List Of Arrays Into A Pandas Dataframe
So I have a list of arrays in Python: [[0, 1, 0, 1], [1, 0, 1, 1], [0, 1, 1, 1]]. I would like to make this list of arrays into a Pandas dataframe, with each array being a row. Is
Solution 1:
No need to do all that splitting, etc. If you have it as a list of lists that is two dimensional (meaning all rows have the same number of elements), you can simply pass it to the DataFrame
constructor:
data = [[0, 1, 0, 1], [1, 0, 1, 1], [0, 1, 1, 1]]
pd.DataFrame(data)
generating the expected:
>>>pd.DataFrame(data)
0 1 2 3
0 0 1 0 1
1 1 0 1 1
2 0 1 1 1
Post a Comment for "Getting A List Of Arrays Into A Pandas Dataframe"