u
This commit is contained in:
1 parent
bb780a42ab
commit
d3145e3dc5
19 files changed
+15364
-416
No files matched your search
@@ -0,0 +1,33 @@
|
||||
import pandas as pd
|
||||
import random
|
||||
import string
|
||||
|
||||
# 配置
|
||||
rows = 10000
|
||||
cols = 20
|
||||
|
||||
# 生成列名
|
||||
columns = [f"列{i+1}" for i in range(cols)]
|
||||
|
||||
# 生成数据
|
||||
data = []
|
||||
for _ in range(rows):
|
||||
row = []
|
||||
for _ in range(cols):
|
||||
# 随机数字或者随机字符串
|
||||
if random.random() < 0.5:
|
||||
row.append(random.randint(1, 10000)) # 随机数字
|
||||
else:
|
||||
row.append(''.join(random.choices(string.ascii_uppercase, k=5))) # 随机5个字母
|
||||
data.append(row)
|
||||
|
||||
# 创建 DataFrame
|
||||
df = pd.DataFrame(data, columns=columns)
|
||||
|
||||
# 保存 Excel
|
||||
df.to_excel("随机20列10000行.xlsx", index=False)
|
||||
|
||||
# 或者保存 CSV
|
||||
df.to_csv("随机20列10000行.csv", index=False, encoding='utf-8-sig')
|
||||
|
||||
print("生成完成!")
|
||||
Reference in new issue
Block a user