简体   繁体   English

如何在python中制作未配对的数据

[英]How to make unpaired data in python

My data is in this format我的数据是这种格式

ID         input_1         input_2
1          'hello'         'greeting'
2          'algorithm'     'computer science'
.             .               .
.             .               .

The input_1 and input_2 can be viewed as the pair data, is there a way or a library in python to shuffle them to make input_1 and input_2 are not paired? input_1 和 input_2 可以看作是成对的数据,python 中有没有办法或者库可以将它们打乱,使 input_1 和 input_2 不成对?

I think you can use numpy.random.permutation :我认为你可以使用numpy.random.permutation

df.input_1 = np.random.permutation(df.input_1)
print (df)
   ID      input_1             input_2
0   1  'algorithm'          'greeting'
1   2      'hello'  'computer science'

You can use the random module - which funnily enough has a shuffle function!您可以使用随机模块 - 有趣的是它具有随机播放功能!

random.shuffle(input_1) random.shuffle(input_1)

(note that shuffle operates in place, yuck) (请注意,shuffle 操作到位,糟糕)

将数据作为数据帧读取,然后使用它的索引df.ix[row_number,column_number]处理它并获取您想要获取的内容并相应地进行处理。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM