• pandas(三):pandas读取excel


    一、代码如下

    import pandas as pd
    
    class ProcessData(object):
        def __init__(self):
            #self.path = "../data/new_data/随机抽听_1.xls"
            #self.path = "../data/new_data/无意义核对语料.xlsx"
            self.path = "../data/new_data/0520新增语义.xlsx"
        def write_suiji(self):
            readbook = pd.read_excel(self.path, sheet_name="sheet1")
            s1 = readbook["语句"]
            y = readbook["标注大类"]
            with open("../data/train.txt", "a+", encoding="utf8") as f:
                for s,l in zip(s1, y):
                    s = s.replace(" ", "").replace("
    ", "").replace("
    ", "").replace("	", "")
                    l = l.replace(" ", "").replace("
    ", "").replace("
    ", "").replace("	", "")
                    line = l + "  " + s + "
    "
                    #f.write(l + "  " + s + "
    ")
        def get_nomeans(self):
            readbook = pd.read_excel(self.path, sheet_name="Sheet1")
            s1 = readbook["客户语句"]
            y = readbook["语义小类"]
            with open("../data/train.txt", "a+", encoding="utf8") as f:
                for s,l in zip(s1, y):
                    s = s.replace(" ", "").replace("
    ", "").replace("
    ", "").replace("	", "")
                    l = l.replace(" ", "").replace("
    ", "").replace("
    ", "").replace("	", "")
                    line = l + "  " + s + "
    "
                    f.write(l + "  " + s + "
    ")
        def get_wenti(self):
            readbook = pd.read_excel(self.path, sheet_name="Sheet1")
            s1 = readbook["客户话术"]
            y = readbook["语义"]
            with open("../data/train.txt", "a+", encoding="utf8") as f:
                for s,l in zip(s1, y):
                    s = s.replace(" ", "").replace("
    ", "").replace("
    ", "").replace("	", "")
                    l = l.replace(" ", "").replace("
    ", "").replace("
    ", "").replace("	", "")
                    f.write(l + "  " + s + "
    ")
        def get_0520(self):
            readbook = pd.read_excel(self.path, sheet_name="Sheet1")
            s1 = readbook["客户语句"]
            y = readbook["语义"]
            with open("../data/train.txt", "a+", encoding="utf8") as f:
                for s,l in zip(s1, y):
                    s = s.replace(" ", "").replace("
    ", "").replace("
    ", "").replace("	", "")
                    l = l.replace(" ", "").replace("
    ", "").replace("
    ", "").replace("	", "")
                    f.write(l + "  " + s + "
    ")
    
        def get_fangshi(self):
            dataLine = []
            with open("../data/new_data/还款方式语料.txt", "r", encoding="utf8") as f:
                for line in f.readlines():
                    sentence = line.replace(" ", "").replace("
    ", "").replace("	", "").replace("
    ", "")
                    dataLine.append(sentence)
            with open("../data/train.txt", "a+", encoding="utf8") as f:
                for data in dataLine:
                    s = data
                    l = "支付宝微信号是多少"
                    f.write(l + "  " + s + "
    ")
    
    if __name__ == '__main__':
        ProcessData().get_fangshi()
  • 相关阅读:
    C++ VC实现对话框窗口任意分割
    C++ 关于滚动条的滚动问题
    C++ 自定义控件的移植(将在其它程序中设计的自定义控件,移植到现在的系统中)
    C++ 动态创建按钮及 按钮的消息响应
    C++ Custom Control控件 向父窗体发送对应的消息
    C++ MFC 改变控件大小和位置
    C++ 使用VS2010创建MFC ActiveX工程项目
    VC++ 自定义控件的建立及使用方法
    C++ CTreeview的checkbox使用方法
    C++ vc中怎么使用SendMessage自定义消息函数
  • 原文地址:https://www.cnblogs.com/zhangxianrong/p/14858615.html
Copyright © 2020-2023  润新知