使用Pandas操作Excel

# -*- coding: utf-8 -*-
import pandas
import os


def getScriptPath():
    return os.path.split(os.path.realpath(__file__))[0]


writer = pandas.ExcelWriter(getScriptPath() + '/output.xlsx')

data = [['Alex', 10], ['Bob', 12], ['Clarke', 13]]
df = pandas.DataFrame(data, columns=['Name', 'Age'])
df.to_excel(writer, 'NameAndAge1')
df.to_excel(writer, 'NameAndAge2')

writer.save()

效果图

参考文章:

https://www.yiibai.com/pandas/python_pandas_dataframe.html

发布了31 篇原创文章 · 获赞 11 · 访问量 3万+

猜你喜欢

转载自blog.csdn.net/MrRight17/article/details/83789211