简体   繁体   English

使用 pd.pivot_table,但没有任何结果

[英]Use pd.pivot_table, but no any result

import pandas as pd
import numpy as np

df1=pd.read_csv('train.csv')
df1=df1.drop("Cabin",axis=1)
df1['Embarked'].fillna(method='ffill',inplace=True)
df1['Age'].fillna(value=df1['Age'].mean(),inplace=True)
pd.pivot_table(df1, index=['Survived'], values=['Age'], aggfunc='std', margins=True)

I was writing a ML code, Survived was int and Age was float, but there was no any respond after I ran the code.我在写一个ML代码,Survived是int,Age是float,但是运行代码后没有任何响应。

In reference book, it will should show me an analysis form, but this code didn't.在参考书中,它应该会给我一个分析表,但是这段代码没有。

If you are working on IDE, not Jupyter Notebook, the code does not show any result.如果您使用的是 IDE,而不是 Jupyter Notebook,则代码不会显示任何结果。

You can create a new dataframe and see the pivoted result as follows:您可以创建一个新的 dataframe 并查看旋转结果如下:

df2 = pd.pivot_table(df1, index=['Survived'], values=['Age'], aggfunc='std', margins=True)
print(df2)

If you just want to see the result without assigning the pivoted dataframe:如果您只想查看结果而不分配旋转的 dataframe:

print(pd.pivot_table(df1, index=['Survived'], values=['Age'], aggfunc='std', margins=True))

Many examples assume that you are working on Jupyter Notebook, which shows/prints variables without print function.许多示例假设您正在使用 Jupyter Notebook,它显示/打印变量而不print function。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM