Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
180 views
in Technique[技术] by (71.8m points)

python - What is the difference between sum() and count() in pandas?

Can you help me understand the difference between the statements mentioned below? Given that Survived column contains binary data (0,1), they give different answers:

df_train[df_train.Sex == 'female'].Survived.count()
df_train[df_train.Sex == 'female'].Survived.sum()
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

sum() is for like 1+0 = 1. if data is 3 and 3 then it return 6.

count() return number of row. so it will return 2.

simple :)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...