简体   繁体   English

Pandas DataFrame构造函数需要列表输入吗?

[英]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.

相关问题 Python Pandas Dataframe构造函数将列表转换为字符串 - Python Pandas Dataframe Constructor Converts List to String Pandas DataFrame 构造函数对行进行排序,即使使用 OrderedDict 作为输入 - Pandas DataFrame constructor sorts rows, even with OrderedDict as input 将 Pandas 数据帧转换为列表列表以输入到 RNN - Converting a pandas dataframe to a list of lists for input into an RNN 给定系列列表时,熊猫“未正确调用 DataFrame 构造函数” - pandas "DataFrame constructor not properly called" when given a list of Series Calling a Python function/class that takes an entire pandas dataframe or series as input, for all rows in another dataframe - Calling a Python function/class that takes an entire pandas dataframe or series as input, for all rows in another dataframe Pandas DataFrame 耗时太长 - Pandas DataFrame takes too long 在从其他列获取输入的 Pandas 数据框中填充新列 - populate new column in a pandas dataframe which takes input from other columns ValueError:DataFrame 构造函数未正确调用! 当将列表中的字典覆盖到 pandas dataframe - ValueError: DataFrame constructor not properly called! when coverting dictionaries within list to pandas dataframe pandas数据帧列表清单 - List of list to pandas dataframe pandas,read_excel, usecols with list input 生成一个空的数据框 - pandas,read_excel, usecols with list input generating an empty dataframe
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM