pandas 传递值的熊猫数据框形状为 (1, 4),索引表示 (4, 4)

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/50874117/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 05:42:20  来源:igfitidea点击:

pandas dataframe Shape of passed values is (1, 4), indices imply (4, 4)

pandasdataframeshape

提问by saias

I am trying to create a pandas dataframe with one row using and ended up testing the following simple line of code:

我正在尝试使用一行创建一个Pandas数据框,并最终测试了以下简单的代码行:

df = pd.DataFrame([1,2,3,4], columns=['a', 'b', 'v', 'w'])

Although this seems very simple i get the following error

虽然这看起来很简单,但我收到以下错误

Shape of passed values is (1, 4), indices imply (4, 4)

I have seen a few answers on this issues but all provide a way around it that doesn't explain why this happens and does not apply in my case.

我已经看到了一些关于这个问题的答案,但都提供了一种解决方法,它不能解释为什么会发生这种情况,也不适用于我的情况。

Thanks is advance.

谢谢是提前。

回答by nimrodz

you need to change the list of values to [[1,2,3,4]]

您需要将值列表更改为 [[1,2,3,4]]

df = pd.DataFrame([[1,2,3,4]], columns=['a', 'b', 'v', 'w'])