import pandas as pd
import time
def pandasWrite():
t0 = time.time()
colname = [str(i) for i in range(550)]
df = pd.DataFrame(columns=colname)
for i in range(100):
df.loc[len(df)] = dict(zip(colname, range(550)))
t1 = time.time()
df.to_csv("temp.csv")
print("pandas 存储数据用时:", t1-t0)
# print(df)
def fileWrite():
t0 = time.time()
colname = [str(i) for i in range(550)]
with open("temp1.txt", 'w', encoding='utf-8') as f:
f.write('\t'.join(x for x in colname))
for i in range(100):
f.write('\t'.join(str(x) for x in range(550))+'\n')
t1 = time.time()
print("写文本 存储数据用时:", t1-t0)
pandasWrite()
fileWrite()