Python 一个数据帧相对于另一个数据帧的随机顺序

Python 一个数据帧相对于另一个数据帧的随机顺序,python,pandas,random,Python,Pandas,Random,我的结构如下: 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)

我的结构如下:

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]
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
    
从字面上看,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中对应的内容。例如:

CN0120 corresponds to ST030
CN0121 corresponds to ST030
....
CN0166 corresponds to ST040
CN0167 corresponds to ST040
...
CN0171 corresponds to ST050
...
数据_Cnx和数据_Srv可以可视化如下:

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]
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
    

我想用,但显然它用整数作为参数。您对如何实现这一点有更简单的想法吗?

我发现以下方法很有效:

bigdata = pd.concat([data_Srv,data_Cnx], axis=1)
bigdata.sample(n = 20)

如果有人提出一个更好的主意,我会乐意尝试:

问题是什么?