Reputation: 2470
The pandas documentation for the DataFrame constructor lists the following argument types for the data argument: numpy ndarray (structured or homogeneous), dict, or DataFrame. Yet it clearly accepts a list of lists (see below). I'm relatively new to pandas and just running through a bunch of tests/examples. Does pandas generally accept python lists in place of ndarrays?
import pandas as pd
DF_From_List_Input = pd.DataFrame([[1,2,3],[4,5,6]]) #works fine!
Upvotes: 1
Views: 327
Reputation: 33793
Yes, Pandas generally accepts Python lists in place of ndarrays. Looking at the source code for the DataFrame class, there's an explicit check for this, currently on line 255, followed by logic for creating a DataFrame.
elif isinstance(data, (list, types.GeneratorType)):
Anecdotally, I've never run into any issues passing a list of lists to the DataFrame constructor.
Upvotes: 1