pandas操作excel

根据.conf配置文件,拿到要读出的列名,一行一个字典,存放于列表里

pandas读取read_excel和to_excel各参数详解:https://blog.csdn.net/u010801439/article/details/80052677

pandas读取excel常用操作: https://www.cnblogs.com/liulinghua90/p/9935642.html

# -*- coding: utf-8 -*-
# @Time    : 2019/3/27 13:35
# @Author  : guigle
# @File    : resd_excel.py
# @Software: PyCharm

import configparser
import pandas


def load_excel():
    data01 = list()
    # data02 = list()
    df_01 = pandas.read_excel("resident_export_212737441126158336.xlsx")
    # 对值为nan的改为 ''
    df_02 = df_01.where(df_01.notnull(), "")
    # df_02 = df_01.fillna('')

    # df_02 = pandas.read_excel("resident_export_212737441126158336.xlsx", sheet_name=1)
    # pandas读取excel时产生Unnamed:列  需要进行删除 
    # old_titles = df_01.columns  # 读取表格标题行
    # for title in old_titles:
    #     if 'Unnamed' in title.split(":"):
    #         del df_01[title]
    temp_path = 'resident_temp.conf'
    cf = configparser.ConfigParser()
    cf.read(temp_path, encoding='utf-8')
    # 根据配置文件拿到要筛选的表格标题
    colum_li = cf.options('residentList')

    for i in df_02.index.values:
        # row_data = df_02.ix[i, colum_li].to_dict()
        # 不指定读取哪些列,默认读出所有列
        row_data = df_02.loc[i, colum_li].to_dict()
        data01.append(row_data)
    # for j in df_02.index.value:
    #     row_data = df_01.loc[j,].to_dict()
    #     data02.append(row_data)
    print(data01)
    # print(data02)


load_excel()

 

你可能感兴趣的:(自动化工具用到技术点)