基于的python的文件判断、处理,地址存表的模块

import pandas as pd
import numpy as np
data = [['E:/桌面/数据', ".csv",1], ['K:/文件名', ".csv", 1], 
        ['E:/桌面/数据2', ".csv", 1]]
df = pd.DataFrame(data, columns=['address',"format", 'times'])
df

 做表

df.to_csv("E:/桌面/地址.csv",index=True)

保存

        def address(address):
            flie_a = pd.read_csv("E:/桌面/地址.csv")
            flie_a.drop(columns='Unnamed: 0', axis=1, inplace=True)
            # print(flie)
            row = flie_a.loc[flie_a["address"] == address]
            index = (row.index).tolist()
            if address == "调用事件":
                flie_s = flie_a.groupby("address").max().sort_values("times", ascending=False)
                return flie_s.index,"无"
            else:
                pass
            if os.path.exists(address) == True:
                # print("可以找到文件")
                name = os.path.split(address)
                f = name[1].split('.')
                address = name[0] + "/" + f[0]
                f = "." + f[1]
            elif os.path.exists(address) == False:
                # print("找不到文件")
                f = ""
                if os.path.exists(address + ".csv") == True:
                    f = ".csv"
                elif os.path.exists(address + ".xls") == True:
                    f = ".xls"
                elif os.path.exists(address + ".xls") == True:
                    f = ".xlsx"
            else:
                print("其他问题")
                pass
            # print(address+f)
            if os.path.exists(address + f) == True:
                if row.empty == True:
                    flie_a = flie_a.append({"address": address, "format": f, "times": 1}, ignore_index=True)
                elif row.empty == False:
                    flie_a.loc[index] = [address, f, int(row["times"].values) + 1]
                else:
                    pass
                flie_a.to_csv("E:/桌面/地址.csv")
                flie_s = flie_a.groupby("address").max().sort_values("times", ascending=False)
                # print(flie_s)
                print(row["format"].values)
                if row["format"].values == None:
                    r ="无"
                elif row["format"].values != None:
                    r=row["format"].values[0]
                else:
                    r = "无"
                return flie_s.index, r

            else:
                return "无", "无"
                pass
        add ="调用事件"
        get_a,get_f = address(add)
        title = st.sidebar.text_input('输入地址', '')
        if title !="":
            if st.sidebar.button("是否用此地址"):
                get_a,get_f = address(title)
                if get_f =="无":
                    get_a, get_f = address(add)
            else:
                pass
        title1 = st.sidebar.selectbox("选择文件",get_a)
        get_a, get_f = address(title1)
        sep = st.sidebar.selectbox("文件分隔符", (",", "\t","|"))
        encoding = st.sidebar.selectbox("文件字符类型", ("GBK", "UTF-8"))
        header = st.sidebar.selectbox("表头", (int("0"), None,[0,1,3]))
        flie = pd.read_csv(title1+get_f, encoding=encoding,sep= sep,header=header)
        stats = os.stat(title1+get_f)
        st.write("读取文件成功!文件大小为:%.1f" % (stats.st_size / 1024 / 1024), "MB")

        def address(address):
            flie_a = pd.read_csv("E:/桌面/地址.csv")
            flie_a.drop(columns='Unnamed: 0', axis=1, inplace=True)
            # print(flie)
            row = flie_a.loc[flie_a["address"] == address]
            index = (row.index).tolist()
            if address == "调用事件":
                flie_s = flie_a.groupby("address").max().sort_values("times", ascending=False)
                return flie_s.index,"无"
            else:
                pass
            if os.path.exists(address) == True:
                # print("可以找到文件")
                name = os.path.split(address)
                f = name[1].split('.')
                address = name[0] + "/" + f[0]
                f = "." + f[1]
            elif os.path.exists(address) == False:
                # print("找不到文件")
                f = ""
                if os.path.exists(address + ".csv") == True:
                    f = ".csv"
                elif os.path.exists(address + ".xls") == True:
                    f = ".xls"
                elif os.path.exists(address + ".xls") == True:
                    f = ".xlsx"
            else:
                print("其他问题")
                pass
            # print(address+f)
            if os.path.exists(address + f) == True:
                if row.empty == True:
                    flie_a = flie_a.append({"address": address, "format": f, "times": 1}, ignore_index=True)
                elif row.empty == False:
                    flie_a.loc[index] = [address, f, int(row["times"].values) + 1]
                else:
                    pass
                flie_a.to_csv("E:/桌面/地址.csv")
                flie_s = flie_a.groupby("address").max().sort_values("times", ascending=False)
                # print(flie_s)
                print(row["format"].values)
                if row["format"].values == None:
                    r ="无"
                elif row["format"].values != None:
                    r=row["format"].values[0]
                else:
                    r = "无"
                return flie_s.index, r

            else:
                return "无", "无"
                pass
        add ="调用事件"
        get_a,get_f = address(add)
        title = st.sidebar.text_input('输入地址', '')
        if title !="":
            if st.sidebar.button("是否用此地址"):
                get_a,get_f = address(title)
                if get_f =="无":
                    get_a, get_f = address(add)
            else:
                pass
        title1 = st.sidebar.selectbox("选择文件",get_a)
        get_a, get_f = address(title1)
        sep = st.sidebar.selectbox("文件分隔符", (",", "\t","|"))
        encoding = st.sidebar.selectbox("文件字符类型", ("GBK", "UTF-8"))
        header = st.sidebar.selectbox("表头", (int("0"), None,[0,1,3]))
        flie = pd.read_csv(title1+get_f, encoding=encoding,sep= sep,header=header)
        stats = os.stat(title1+get_f)
        st.write("读取文件成功!文件大小为:%.1f" % (stats.st_size / 1024 / 1024), "MB")

这里用的是streamlit框架