Python 给熊猫打电话后的困惑结果
我通过以下方式获取数据:Python 给熊猫打电话后的困惑结果,python,pandas,Python,Pandas,我通过以下方式获取数据: train.MSZoning.value_counts() Out: RL 1151 RM 218 FV 65 RH 16 C (all) 10 Name: MSZoning, dtype: int64 C (all) => 0 Fv => 1 RH => 2 RL => 3 RM => 4 我试着用这种方式对它进行编码: train.MSZoning.
train.MSZoning.value_counts()
Out:
RL 1151
RM 218
FV 65
RH 16
C (all) 10
Name: MSZoning, dtype: int64
C (all) => 0
Fv => 1
RH => 2
RL => 3
RM => 4
我试着用这种方式对它进行编码:
train.MSZoning.value_counts()
Out:
RL 1151
RM 218
FV 65
RH 16
C (all) 10
Name: MSZoning, dtype: int64
C (all) => 0
Fv => 1
RH => 2
RL => 3
RM => 4
所以,我想我会再次打印value\u counts()
,如下所示:
Out:
0 10
1 65
2 16
3 1151
4 218
我试着像这样使用熊猫。获取傻瓜():
t = pd.get_dummies(train.MSZoning)
print(t)
Out:
C (all) FV RH RL RM
0 0 0 0 1 0
1 0 0 0 1 0
2 0 0 0 1 0
3 0 0 0 1 0
4 0 0 0 1 0
5 0 0 0 1 0
...
我打印pd.Dataframe(t).descripe()
以获得它的描述
C (all) FV RH RL RM
count 1460.000000 1460.000000 1460.000000 1460.000000 1460.000000
mean 0.006849 0.044521 0.010959 0.788356 0.149315
std 0.082505 0.206319 0.104145 0.408614 0.356521
min 0.000000 0.000000 0.000000 0.000000 0.000000
25% 0.000000 0.000000 0.000000 1.000000 0.000000
50% 0.000000 0.000000 0.000000 1.000000 0.000000
75% 0.000000 0.000000 0.000000 1.000000 0.000000
max 1.000000 1.000000 1.000000 1.000000 1.000000
但是当我试图用这种方式使用pd.get_dummies()时,我得到了一些不同的东西,这让我感到困惑:
train.MSZoning = pd.get_dummies(train.MSZoning)
Out:
print(train.MSZoning)
0 1
1 1
2 1
3 1
4 1
5 1
...
train.MSZoning.describe()
Out:
count 1460.000000
mean 0.993151
std 0.082505
min 0.000000
25% 1.000000
50% 1.000000
75% 1.000000
max 1.000000
Name: MSZoning, dtype: float64
我想知道为什么调用函数get_dummies()
并分配它之后会得到两个不同的结果
如果不介意的话,有人能帮我吗
衷心感谢。我认为您应该重新考虑这一行:
train.MSZoning = pd.get_dummies(train.MSZoning)
您正在将数据帧
分配给系列
不确定那里发生了什么,但我猜这不是你的意图。观察得好+1@ScottBoston谢谢不知道那里发生了什么。