import time
import threading
import datetime
import pandas as pd
class Book():
def __init__(self,id,name,author,comment,content,isbn,summary,title,topic):
self.id=id
self.name=name
self.author=author
self.comment=comment
self.content=content
self.isbn=isbn
self.summary=summary
self.title=title
self.topic=topic
book_list=[]
t1=datetime.datetime.now()
arr=range(1,1000001)
for a in arr:
book_list.append(Book(a,f'Name_{a}',f'Author_{a}',f'Comment_{a}',f'Content_{a}',f'ISBN_{a}',f'Summary_{a}',f'Title_{a}',f'Topic_{a}'))
print(f'Init time cost {datetime.datetime.now()-t1}')
book_data=[]
t1=datetime.datetime.now()
for bk in book_list:
dic={
'Id':bk.id,
'Name':bk.name,
'Author':bk.author,
'Comment':bk.comment,
'Content':bk.content,
'ISBN':bk.isbn,
'Summary':bk.summary,
'Title':bk.title,
'Topic':bk.topic
}
book_data.append(dic)
print(f'Convert book_data to list with keyvalue items cost:{datetime.datetime.now()-t1}')
excelFile=f'book_data_{datetime.datetime.now().strftime('%Y%m%d%H%M%S%f')}.csv'
t1=datetime.datetime.now()
df=pd.DataFrame(book_data)
df.to_csv(excelFile,encoding='utf-8',index=False)
print(f'Store in csv file cost {datetime.datetime.now()-t1},excel file:{excelFile}')
excelFile=f'book_dic_{datetime.datetime.now().strftime('%Y%m%d%H%M%S%f')}.csv'
t1=datetime.datetime.now()
df=pd.DataFrame([bk.__dict__ for bk in book_list])
df.to_csv(excelFile,encoding='utf-8',index=False)
print(f'Store book_dic_ in csv file cost {datetime.datetime.now()-t1},excel file:{excelFile}')
![image]()
![image]()
![image]()
![image]()