pandas 'DataFrame' 对象没有属性 'to_frame'
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/49566862/
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
'DataFrame' object has no attribute 'to_frame'
提问by Serdia
I am new to python. Just following the tutorial: https://www.hackerearth.com/practice/machine-learning/machine-learning-projects/python-project/tutorial/
我是python的新手。只需遵循教程:https: //www.hackerearth.com/practice/machine-learning/machine-learning-projects/python-project/tutorial/
This is the dataframe miss:
这是数据帧未命中:
miss = train.isnull().sum()/len(train)
miss = miss[miss>0]
miss.sort_values(inplace = True)
miss
Electrical 0.000685
MasVnrType 0.005479
MasVnrArea 0.005479
BsmtQual 0.025342
BsmtCond 0.025342
BsmtFinType1 0.025342
BsmtExposure 0.026027
BsmtFinType2 0.026027
GarageCond 0.055479
GarageQual 0.055479
GarageFinish 0.055479
GarageType 0.055479
GarageYrBlt 0.055479
LotFrontage 0.177397
FireplaceQu 0.472603
Fence 0.807534
Alley 0.937671
MiscFeature 0.963014
PoolQC 0.995205
dtype: float64
Now I just want to visualize those missing values"
现在我只想可视化那些缺失的值”
#visualising missing values
miss = miss.to_frame()
miss.columns = ['count']
miss.index.names = ['Name']
miss['Name'] = miss.index
And this is the error I got:
这是我得到的错误:
AttributeError Traceback (most recent call last)
<ipython-input-42-cd3b25e8862a> in <module>()
1 #visualising missing values
----> 2 miss = miss.to_frame()
C:\Users\Username\AppData\Local\Continuum\Anaconda3\lib\site-packages\pandas\core\generic.py in __getattr__(self, name)
2742 if name in self._info_axis:
2743 return self[name]
-> 2744 return object.__getattribute__(self, name)
2745
2746 def __setattr__(self, name, value):
AttributeError: 'DataFrame' object has no attribute 'to_frame'
What am I missing here?
我在这里错过了什么?
回答by Morse
Check print(type(miss))
it should be <class 'pandas.core.series.Series'>
检查print(type(miss))
它应该是<class 'pandas.core.series.Series'>
You have is dataframe, somewhere in the code you are doing wrong.
您拥有的是数据框,在代码中的某处您做错了。
df = pd.DataFrame()
df.to_frame()
Traceback (most recent call last):
File "<input>", line 1, in <module>
File "C:\Users\UR_NAME\AppData\Local\Programs\Python\Python36\lib\site-packages\pandas\core\generic.py", line 3614, in __getattr__
return object.__getattribute__(self, name)
AttributeError: 'DataFrame' object has no attribute 'to_frame'
I traced the tutorial, and below is the order flow
我跟踪了教程,下面是订单流程
train = pd.read_csv("train.csv")
print(type(train)) # <class 'pandas.core.frame.DataFrame'>
miss = train.isnull().sum()/len(train)
print(type(miss)) # <class 'pandas.core.series.Series'>
miss = train.isnull().sum()/len(train)
converts in into pandas.core.series.Series
from pandas.core.frame.DataFrame
miss = train.isnull().sum()/len(train)
转换成pandas.core.series.Series
从pandas.core.frame.DataFrame
You are probably messed code at this place.
你可能在这个地方搞砸了代码。