[英]Pandas DataFrame constructor takes list input?
The pandas documentation for the DataFrame constructor lists the following argument types for the data argument: numpy ndarray (structured or homogeneous), dict, or DataFrame. DataFrame构造函数的pandas 文档列出了data参数的以下参数类型:numpy ndarray(结构化或同构),dict或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?
大熊猫通常接受python列表代替ndarrays吗?
import pandas as pd
DF_From_List_Input = pd.DataFrame([[1,2,3],[4,5,6]]) #works fine!
Yes, Pandas generally accepts Python lists in place of ndarrays. 是的,Pandas通常接受python列表代替ndarray。 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.
查看DataFrame类的源代码 ,对此进行了显式检查(当前位于255行),然后是用于创建DataFrame的逻辑。
elif isinstance(data, (list, types.GeneratorType)):
Anecdotally, I've never run into any issues passing a list of lists to the DataFrame constructor. 有趣的是,我从未遇到过将列表列表传递给DataFrame构造函数的任何问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.