[英]Pandas DataFrame: Grouping Rows?
我正在努力完成的两个挑战。
这是挑战的第一部分。 对于挑战的第二部分:
该表是我正在寻找的结果:
(如果在 python 中这样做似乎是一个糟糕的主意,并且在 excel 中更容易做到,那么这也是一个很好的答案,如果是这样的话,只需要有人可以指出我正确的方向,然后我可以将 a.ZCC8D68C551C4A9AFDZDE531 导入到一个 DataFrame )
Company Name Apple App Views Apple Install Droid View DoidInstall
0 Zynga 5000 0.50 0.00 0.00
1 Zynga 0 0 15000 0.33
2 EA Mobile 22000 0.57 0.00 0.00
3 EA Mobile 0 0 26000 0.49
import numpy as np
import pandas as pd
# create array with selected values
app_views = [4000, 2222, 9999]
app_install = [0, 0.3, 0.83]
# generate a numpy array with 3 random integeres between 1000 to 10,000
random_app_views = np.random.randint(1000, 10000, size=3)
# generate a numpy array with 3 random numbers between 0 to 1
random_app_install = np.random.uniform(0, 1, size=3)
df = pd.DataFrame({
'app_views': app_views,
'app_install_rate': app_install,
'random_app_views': random_app_views,
'random_app_install': random_app_install
})
将产生一个 DataFrame 像:
app_views | 应用安装 | random_app_views | random_app_install | |
---|---|---|---|---|
0 | 4000 | 0.00 | 2196 | 0.626350 |
1 | 2222 | 0.30 | 6917 | 0.412264 |
2 | 9999 | 0.83 | 3291 | 0.303517 |
希望这就足够了,祝你好运
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.