Pandas storage excel method

a_data=pd.DataFrame()#你的数据集 

a_data.to_excel(excel_writer= r"#你想要存储的路径\\你想要存储的文件名.xlsx")

for example

a_data=pd.DataFrame({'标题':cc_title,'发布时间':cc_issue_time,'notice':cc_notice,'预算(元)':cc_budget,'发布地区':cc_reigon,'详细网址1': cc_web,'详细网址2': cc})

a_data.to_excel(excel_writer= r"C:\\Users\\Administrator\\Desktop\\导出结果(一个巨大的爬虫).xlsx")

Note that double "\\" or one-way backslash "/" must be used

for example

#可以这样写
C:\\Users\\Administrator\\Desktop\\导出结果(一个巨大的爬虫).xlsx
#或者这样写
C:/Users/Administrator/Desktop/导出结果(一个巨大的爬虫).xlsx

demo results

 In fact, in addition to the pandas library can handle the problem of excel storage

and many other libraries

Such as xlwt library

import xlwt
workbook=xlwt.Workbook(encoding='utf-8')

booksheet=workbook.add_sheet('Sheet 1', cell_overwrite_ok=True)

DATA=((数据标签的位置),

(第一行数据),

(第二行数据),
 
#以此类推

)

for i,row in enumerate(DATA):
    for j,col in enumerate(row):

       booksheet.write(i,j,col)

       workbook.save('你想存储的文件名.xls')

#默认存储在Desktop中

but it is not recommended to use

reason:

Pandas saves and reads in addition to excel

In fact, there are many data processing functions

For example pd.DataFrame() pd.read_csv() etc.

#举例说明
pd.DataFrame() # 自己创建数据框,用于练习

pd.read_csv() # 从CSV⽂件导⼊数据

pd.read_table() # 从限定分隔符的⽂本⽂件导⼊数据

pd.read_excel() # 从Excel⽂件导⼊数据

pd.read_sql() # 从SQL表/库导⼊数据

pd.read_json() # 从JSON格式的字符串导⼊数据

pd.read_html() # 解析URL、字符串或者HTML⽂件,抽取其中的tables表格

The above examples basically include common forms for daily data import.

For commonly used data analysis pandas basic fitting

Really good for processing before data analysis

If you don't use pandas, you will often fall into the dilemma of patching together the library later

The work of data processing can become cumbersome.

It is recommended that novices study the pandas library more

Guess you like

Origin blog.csdn.net/weixin_48572116/article/details/126232652