假设pandas dataframe
In [23]: df = pd.DataFrame()
...: df['Wafer_Id'] = [0,0,0,1,1,1,2,2,3]
...: df['v1'] = np.random.normal(0, 1, 9)
...: df['v2'] = np.random.normal(0, 1, 9)
In [23]:
In [24]: df
Out[24]:
Wafer_Id v1 v2
0 0 0.050987 -1.524646
1 0 0.784595 -0.545002
2 0 1.005748 0.588026
3 1 1.146895 0.196029
4 1 1.570850 -1.609470
5 1 -0.393617 1.091749
6 2 1.366572 -2.189071
7 2 1.444561 0.378211
8 3 1.327378 0.213290
对于wafer_id=0
或1
,有3
行,2
和wafer_id = 2
只有3
我想为0
添加一行wafer_id=2
2
行和0
行wafer_id=3
,以便每个晶圆索引都有<head>
相同数量的样本。
我该怎么做?