如何在数据集中的现有列中添加更多的随机值行



我想在下面提供的数据集的每列中再添加十行。它应该添加从以下范围内的随机整数值:

  1. 20-27温度
  2. 湿度为40-55
  3. 湿度为150-170

数据集:温度湿度湿度

0 22        46      0 
1 36        41.4    170 
2 18        69.3    120 
3 21        39.3    200 
4 39        70      150 
5 22        78      220 
6 27        65      180 
7 32        75      250

我尝试过:将numpy导入为np进口熊猫作为pd

data1=np随机随机随机点(20,27,大小=10(df=pd.DataFrame(数据,列=[温度](

打印(df(

此方法删除所有现有的行值,只给出随机值。我所需要的只是现有的行和附加的随机值。

使用:

df1 = pd.DataFrame({'Temperature':np.random.randint(20,28,size=10),
'Humidity':np.random.randint(40,56,size=10),
'Moisture':np.random.randint(150,171,size=10)})
df = pd.concat([df, df1], ignore_index=True)
print (df)
Temperature  Humidity  Moisture
0            22      46.0         0
1            36      41.4       170
2            18      69.3       120
3            21      39.3       200
4            39      70.0       150
5            22      78.0       220
6            27      65.0       180
7            32      75.0       250
8            20      52.0       158
9            21      45.0       156
10           23      49.0       151
11           24      51.0       167
12           22      45.0       157
13           21      43.0       163
14           26      55.0       162
15           25      40.0       164
16           24      40.0       155
17           20      48.0       150

最新更新