Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Download

📚 The CoCalc Library - books, templates and other resources

132923 views
License: OTHER
1
# 1. Use the `head()` method to get the first ten rows
2
df.head()
3
4
# 2. Use the `drop_duplicates()` method to find all of the distinct names
5
df.names.drop_duplicates().compute()
6
7
# 3. Use selections `df[...]` to find how many positive and negative amounts
8
# there are
9
len(df[df.amount < 0])
10
11
# 3. Use selections `df[...]` to find how many positive and negative amounts
12
# there are
13
len(df[df.amount > 0])
14
15
# 4. Use groupby `df.groupby(df.A).B.func()` to get the average amount per user
16
# ID
17
df.groupby(df.names).amount.mean().compute()
18
19
# 5. Combine your answers to 3 and 4 to compute the average withdrawal
20
# (negative amount) per name
21
df2 = df[df.amount < 0]
22
df2.groupby(df2.names).amount.mean().compute()
23
24