一、安装

windows环境下

pip install xlwt xlrd pandas 

 

二、基础使用

'''
pip install xlwt xlrd
'''
import pandas as pd
FILE_NAME='1_domain.com.xlsx'
if __name__ == '__main__':
    # 读取csv文件
    #dateframe = pd.read_csv(FILE_NAME)
    #读取excel文件
    dateframe =pd.read_excel(FILE_NAME)
    #将excel内容字典化,作为列表元素保存,返回列表,首行作为keys
    items = dateframe.to_dict(orient='records')
    print(items)



    writeContentList = [
        {'记录类型':"CNAME", '主机记录': 'test01', '解析线路': '默认', '记录值': 'x.abc.com', 'MX优先级': '', 'TTL值': 1, '状态(暂停/正常)': '正常', '备注': ''},
        {'记录类型': 'CNAME', '主机记录': 'test02', '解析线路': '默认', '记录值': 'y.abc.com', 'MX优先级': '', 'TTL值': 1, '状态(暂停/正常)': '正常', '备注': ''}
    ]
    # 写入csv文件
    df = pd.DataFrame(writeContentList)
    df.to_csv('1_save_domain.com.csv',index=False,encoding='gbk')

    #写入excel文件
    df = pd.DataFrame(writeContentList)
    df.to_excel('1_save_domain.com.xlsx',sheet_name='Test01',index=False)

 

相关文章:

  • 2022-01-29
  • 2022-12-23
  • 2021-11-08
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-06-30
  • 2021-10-18
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-12-15
  • 2021-10-08
  • 2021-11-05
  • 2022-12-23
相关资源
相似解决方案