34 lines
752 B
Python
34 lines
752 B
Python
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("生成完成!")
|