当前位置: 首页 > news >正文

Python convert class list in CSV file via pandas.dataframe

import time
import threading
import datetime
import pandas as pdclass Book():def __init__(self,id,name,author,comment,content,isbn,summary,title,topic):self.id=idself.name=nameself.author=authorself.comment=commentself.content=contentself.isbn=isbnself.summary=summaryself.title=titleself.topic=topicbook_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

 

http://www.gsyq.cn/news/61943.html

相关文章:

  • RabbitMQ消息分发详解:从默认轮询到智能负载均衡 - 指南
  • 11月26日
  • slkjflksjdklflsdkjfjlksdlkjfsflkjsd
  • 十一月份《代码大全》观后感
  • [KaibaMath]1026 海明码校验位数求解方法的进一步简化
  • 2025年11月【口碑好的】通讯管理机【公司】【推荐】【哪家好】
  • Redhat-9-中编译-EFS-客户端工具-即过程中-报错提示-warning: aws-lc-fips-sys@0.13.9: Building with: CMake-解决方法
  • 05app抓包
  • 实用指南:基于 ComfyUI 的 Stable Diffusion 本地部署与使用教程
  • 2025年设计师与程序员专属:高级感简历模板 TOP5 排行榜
  • 什么是Go语言
  • 人工智能之数据分析 Matplotlib:第一章 简介和安装
  • feature map是什么
  • 重磅!图灵奖得主 Bengio 领衔 30 + 顶流学者联合发文!首次给 AGI 下量化定义
  • 零代码,分钟级定制:我用LLaMA-Factory轻松造了个“票务专家”AI
  • StackOverflow已经死亡了吗
  • 2025AI培训权威排名:AI时代新商学引领行业变革
  • Manim进阶:用背景图片让你的数学视频脱颖而出
  • 2025 AI 培训机构权威推荐榜排名揭晓:AI时代新商学引领行业破局之路
  • Lab4AI与国内顶会展开合作!一键体验 CVPR/ICCV/NeurIPS 顶会论文复现
  • SIGIR会议聚焦包容性AI与多语言技术
  • 详细介绍:VS Code 新旧版本 Remote-SSH 内网离线连接服务器方法(版本 ≤ 1.78.x 及 ≥ 1.79.0)
  • 44(11.24)
  • 47(11.27)
  • 45(11.25)
  • 29(11.3)
  • 26 10.29
  • 50048_基于微信小程序的人事管理系统
  • 二分答案 序列划分
  • 2025年江苏宣传片、网站建设、AI GEO、外贸站、小程序商城公司综合评测与精选服务商推荐