简体   繁体   English

ValueError: DataFrame 构造函数未正确调用

[英]ValueError: DataFrame constructor not properly called

I am trying to create a dataframe with Python, which works fine with the following command:我正在尝试使用 Python 创建一个数据框,它可以使用以下命令正常工作:

df_test2 = DataFrame(index = idx, data=(["-54350","2016-06-25T10:29:57.340Z","2016-06-25T10:29:57.340Z"]))

but, when I try to get the data from a variable instead of hard-coding it into the data argument;但是,当我尝试从变量中获取数据而不是将其硬编码到数据参数中时; eg.例如。 :

r6 = ["-54350", "2016-06-25T10:29:57.340Z", "2016-06-25T10:29:57.340Z"]
df_test2 = DataFrame(index = idx, data=(r6))

I expect this is the same and it should work?我希望这是一样的,它应该有效吗? But I get:但我得到:

 ValueError: DataFrame constructor not properly called!

Reason for the error:错误原因:

It seems a string representation isn't satisfying enough for the DataFrame constructor似乎字符串表示不足以满足 DataFrame 构造函数

Fix/Solutions:修复/解决方案:

import ast
# convert the string representation to a dict
dict = ast.literal_eval(r6) 
# and use it as the input
df_test2 = DataFrame(index = idx, data=(dict)) 

which will solve the error.这将解决错误。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 ValueError DataFrame构造函数未正确调用 - ValueError DataFrame constructor not properly called ValueError:未正确调用 DataFrame 构造函数! 与熊猫 - ValueError: DataFrame constructor not properly called! with pandas ValueError:未正确调用 sarima 的 DataFrame 构造函数 - ValueError: DataFrame constructor not properly called for sarima 如何解决 ValueError: DataFrame 构造函数未正确调用 - How to solve ValueError: DataFrame constructor not properly called ValueError: DataFrame 构造函数未正确调用 (Databricks/Python) - ValueError: DataFrame constructor not properly called (Databricks/Python) 无法修复“ValueError:未正确调用 DataFrame 构造函数!” - Unable to fix “ValueError: DataFrame constructor not properly called!” 接收 ValueError: DataFrame 构造函数未正确调用 - Receiving ValueError: DataFrame constructor not properly called 将列表列表转换为数据框时出现“ ValueError:DataFrame构造函数未正确调用!” - “ValueError: DataFrame constructor not properly called!” while converting list of lists to dataframe 如何修复ValueError:在flask上没有正确调用DataFrame构造函数 - How to fix ValueError: DataFrame constructor not properly called on flask np.array到数据框字典:ValueError:DataFrame构造函数未正确调用 - np.array to dictionary of dataframes: ValueError: DataFrame constructor not properly called
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM