python - 如何使来自多个文件的大数据/代码的所有可能组合。代码超过200、400、1000、20亿
问题描述
我有大量的代码(代码数 = 9898654986.),即使有时它会在多个文件中(10、20、40....甚至 200 位)。我想对这些代码进行所有可能的组合,组合应该打印在多个文件上。但我想要所有可能的组合,例如如果代码 = ab1、aa2、dc3、xx4。所以组合应该像.. ('ab1', 'ab1'), ('ab1', 'aa2'), ('ab1', 'dc3'), ('ab1', 'xx4'), (' aa2', 'ab1'), ('aa2', 'aa2'), ('aa2', 'dc3'), ('aa2', 'xx4'), ('dc3', 'ab1'), (' dc3', 'aa2'), ('dc3', 'dc3'), ('dc3', 'xx4'), ('xx4', 'ab1'), ('ab1', 'aa2'), (' ab1', 'dc3'), (' xx4','xx4')。我这样做的单个文件至少少于一百万个代码。
import os, import pandas as pd, import itertools
os.chdir('C:/Users/Rashid/Desktop/Try')
df = pd.read_excel("code1.xlsx", header=None, index_col=False, dtype=str)
df.columns = ['A']
i = 0
lines = []
for item in itertools.product(df['A'], repeat=4):
lines.append(item)
if len(lines) > 50000:
with open(f'4ta.{i}.txt', 'a') as f:
f.write(''.join(str(lines)))
lines = []
i += 1
解决方案
如果您的所有数据都在df
“A”列中,则:
for i, j in permutations(df["A"], r=2):
print(i, j)
将产生所有可能的排列。
推荐阅读
- python - 使用 mongoclient 我无法在 python 的 mongo 集合中添加 BinData 类型的键
- python - 在同一选项卡中添加多个帧 tkinter python
- javascript - 如何使用 php 将 .docx、xslx、img、txt 等任何文件转换为 PDF 预览?
- javascript - html2canvas 在将其包装在 setTimeout 回调中后可以正常工作,为什么以及什么是完美的解决方案?
- python - 找出一周后创建的最后一个文件名的优雅解决方案?
- excel - 使用 Excel VBA,如何抓取不在表格中的 Web 数据
- php - 我有问题解码 JSON
- node.js - 试图弄清楚如何让客户端(浏览器)发回 jwt 令牌,以便我可以验证
- coldfusion - 使用向上和向下箭头手动排序代码
- c# - Azure 中的反向代理