我有一个测试分数的频率表:
score count
----- -----
77 1105
78 940
79 1222
80 4339
etc
Run Code Online (Sandbox Code Playgroud)
我想显示由频率表总结的样本的基本统计数据和箱线图。(例如,上例的平均值为 79.16,中位数为 80。)
有没有办法在 Pandas 中做到这一点?我见过的所有例子都假设有一个个案表。
我想我可以生成一个个人分数列表,就像这样——
In [2]: s = pd.Series([77] * 1105 + [78] * 940 + [79] * 1222 + [80] * 4339)
In [3]: s.describe()
Out[3]:
count 7606.000000
mean 79.156324
std 1.118439
min 77.000000
25% 78.000000
50% 80.000000
75% 80.000000
max 80.000000
dtype: float64
Run Code Online (Sandbox Code Playgroud)
——但我希望避免这种情况;真实非玩具数据集中的总频率高达数十亿。
任何帮助表示赞赏。
(我认为这是一个与使用describe()与加权数据不同的问题,后者是关于将权重应用于个别情况。)
我使用熊猫创建了一个共现矩阵,如下所示。
import pandas as pd
import numpy as np
lst = [
['a', 'b'],
['b', 'c', 'd', 'e', 'e'],
['a', 'd', 'e'],
['b', 'e']
]
u = (pd.get_dummies(pd.DataFrame(lst), prefix='', prefix_sep='')
.groupby(level=0, axis=1)
.sum())
v = u.T.dot(u)
v.values[(np.r_[:len(v)], ) * 2] = 0
print(v)
Run Code Online (Sandbox Code Playgroud)
输出如下。
a b c d e
a 0 1 0 1 1
b 1 0 1 1 3
c 0 1 0 1 2
d 1 1 1 0 3
e 1 3 2 3 0
Run Code Online (Sandbox Code Playgroud)
我想将上述数据帧转换为(x,y)对。如您所见,输出矩阵是对称的(即,对角线的上部和对角线的下部相似)。因此,我很高兴只从其中一部分获得(x,y)对(例如,仅使用上部)。 …
我有一组可以分组的不同时间序列.例如,下图显示了系列A,B,C和D.然而,A和B在组G1中,C和D在组G2中.
我想在图中通过在左侧添加另一个轴来反映这一点,该轴穿过涡轮组并相应地标记轴.
到目前为止,我尝试过一些东西,但显然不是那么容易.
有些人知道我怎么做吗?
PS:因为我在plot(subplots=True)已经有列的数据框架上使用panda
| G1 | G2 |
|-------|------|
index | A B | C D |
------|-------|------|
Run Code Online (Sandbox Code Playgroud)
可能是大熊猫已经可以为我做到这一点.这就是我使用pandas标签的原因.
我有一个关于在 ImageDataGenerator 上使用 fit() 的问题。我使用 Dense 层成功地批量运行了 MNIST 测试。
以下代码完美运行(验证准确率 98.5%)。
(X_train, y_train), (X_test, y_test) = mnist.load_data()
# separate data into train and validation
from sklearn.model_selection import train_test_split
# Split the data
valid_per = 0.15
X_train, X_valid, y_train, y_valid = train_test_split(X_train, y_train, test_size=valid_per, shuffle= True)
N1 = X_train.shape[0] # training size
N2 = X_test.shape[0] # test size
N3 = X_valid.shape[0] # valid size
h = X_train.shape[1]
w = X_train.shape[2]
num_pixels = h*w
# reshape N1 samples to num_pixels
#x_train …Run Code Online (Sandbox Code Playgroud) 我是熊猫新手。这是一个例子的问题
df = pd.DataFrame(data={'id':['john','joe','zack']})
Run Code Online (Sandbox Code Playgroud)
我知道我可以选择“ id”列包含“ jo”的行,如下所示
mask = df['id'].str.contains('jo')
df[mask]
Run Code Online (Sandbox Code Playgroud)
But suppose that id column is indexed
df = df.set_index('id')
Run Code Online (Sandbox Code Playgroud)
Now how do I select the rows where the index column contains "jo"?