-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Homework Submission 2017-07-06: Lecture 1, Python Data Analysis #2
Labels
Comments
Member List: |
import numpy as np
import pandas as pd
# 二项分布数组
arr = np.random.binomial(1, 0.5, size = (26,4))
# 大于0.5的数字
arr2 = arr[arr>0.5]
# 转化为dataframe
letters = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']
df = pd.DataFrame(arr, index = letters, columns = ['one','two','three','four'])
# 按照two的降序排列 取前五个
df2 = df.sort_values(['two'], ascending = False).iloc[0:5,:]
# 取 one 列
one = df['one']
oneMean = one.mean()
oneSum = one.sum()
oneMid = one.median()
oneVar = one.var() |
@AustinJiangH Very good! Try to use Pythonic way to get 26 letters. You can try |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Please submit your homework for Lecture 1 of Python Data Analysis on 2017-07-06 here.
The text was updated successfully, but these errors were encountered: