我具有以下结构:
data_Cnx = pd.read_csv(path_Connection,sep='\t',header=None)
data_Cnx.columns = ["ConnectionID"]
data_Srv = pd.read_csv(path_Service,sep='\t',header=None)
data_Srv.columns = ["ServiceID"]
可以显示为以下内容:
print(data_Cnx)
ConnectionID
0 CN0120
1 CN0121
2 CN0122
3 CN0123
4 CN0124
... ...
20 CN0166
21 CN0167
22 CN0168
23 CN0171
24 CN0172
[25 rows x 1 columns]
print(data_Srv)
ServiceID
0 ST030
1 ST030
2 ST030
3 ST030
4 ST030
... ...
20 ST040
21 ST040
22 ST040
23 ST050
24 ST050
[25 rows x 1 columns]
从字面上看,data_Cnx
中的每个元素对应于data_Srv
中的一个平行元素,遵守顺序。例如:
CN0120 corresponds to ST030
CN0121 corresponds to ST030
....
CN0166 corresponds to ST040
CN0167 corresponds to ST040
...
CN0171 corresponds to ST050
...
我想拥有另一种结构或不同的data_Cnx
和data_Srv
,其中data_Cnx
的顺序可以是随机的,但总是考虑data_Srv
中对应的内容。例如:
data_Cnx
和data_Srv
可以如下所示:
print(data_Cnx)
ConnectionID
0 CN0120
1 CN0168
2 CN0156
3 CN0133
4 CN0161
... ...
20 CN0121
21 CN0143
22 CN0127
23 CN0151
24 CN0132
print(data_Srv)
[25 rows x 1 columns] ServiceID
0 ST030
1 ST040
2 ST070
3 ST010
4 ST040
... ...
20 ST030
21 ST050
22 ST030
23 ST070
24 ST010
我当时在考虑使用randn,但是显然它使用整数作为参数。您是否更容易实现此想法?
答案 0 :(得分:1)
我只是找到了以下作品:
bigdata = pd.concat([data_Srv,data_Cnx], axis=1)
bigdata.sample(n = 20)
如果有人提出了一个更好的主意,我将开放供您尝试:)