pandas 为什么 df.head() 在 python 中不起作用
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/45489205/
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
Why is df.head() not working in python
提问by Akhil
Hi there everyone I am working on a project with python which needs data frames so I am using pandas but there seem to be a problem to when ever I go and type in print(data.head())
AttributeError: 'list' object has no attribute 'head'
below is the rest of my code any help will be awesome.
大家好,我正在开发一个需要数据帧的 python 项目,所以我正在使用 Pandas,但似乎有一个问题,当我去输入print(data.head())
AttributeError: 'list' object has no attribute 'head'
下面的代码时,任何帮助都会很棒。
import quandl
import pandas as pd
import numpy as np
data = quandl.get_table('WIKI/PRICES')
print(data.head())
回答by Alok Singhal
You need to change the list to a pandas DataFrame first. After that you will be able to do data.head()
. Something like:
您需要先将列表更改为 Pandas DataFrame。之后你就可以了data.head()
。就像是:
df = pd.DataFrame(my_list)