首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >属性错误:‘str’对象没有属性'unique‘(Pandas.unique)

属性错误:‘str’对象没有属性'unique‘(Pandas.unique)
EN

Stack Overflow用户
提问于 2022-01-20 11:18:00
回答 1查看 478关注 0票数 0

在我的脚本中,我使用熊猫模块。当我执行我的file.py时,一切都很好。但是,我已经用auto到-exe将我的file.py转换为file.exe,并得到了一个错误: AttributeError:'str‘对象没有属性'unique’。很奇怪因为它正常工作。变成错误的行: wells=list(file.unique())。谁知道这个问题,请帮帮忙。

代码语言:javascript
复制
import tkinter as tk
import tkinter.filedialog as fd
import pandas as pd
import os
import datetime
from datetime import datetime, date
import numpy as np
pd.set_option('display.notebook_repr_html', False)
pd.set_option('display.max_columns', 80)
pd.set_option('display.max_rows', 200)
pd.set_option('display.width', 800)

def resource_path(relative_path):
    try:
        base_path = sys._MEIPASS
    except Exception:
        base_path = os.path.abspath(".")
    return os.path.join(base_path, relative_path)

def open():
    global file_excel, name
    file_excel = fd.askopenfilename(initialdir='/Desktop',     title='Открыть файл', filetypes = [("Excel", "*.xlsx")])
    name = os.path.basename(file_excel)
    name=os.path.splitext(name)[0]
    file_excel=pd.read_excel(file_excel, skiprows=[0], header=None)
    win.destroy()
    return file_excel, name

win = tk.Tk()
path = resource_path("image.png")
photo = tk.PhotoImage(file=path)
win.iconphoto(False, photo)
win.config(bg='#FFC')
win.title('Конвертация в формат .ev')
win.geometry('400x130+500+500')
win.resizable(False, False)

label_1 = tk.Label(win, text = 'Выберите файл с испытаниями скважин:',
                  bg = '#FFC',
                  font=('Arial', 10, 'bold'),
                  padx=20,
                  pady=10).pack()
btn_1 = tk.Button(win, text = 'Выбрать Excel', 
                 command = open,
                 activebackground = '#6F6',
                 font=('Arial', 12, 'bold'),
                 padx=20,
                 pady=10,  
                 relief = tk.RAISED,
                 bd=2).pack()
win.mainloop()

wells=list(file_excel[0].unique())
file_excel[1] = pd.to_datetime(file_excel[1],   errors='coerce').dt.strftime("%d/%m/%Y")
file_excel[4] = np.where(file_excel[1].str, 'Perforation', np.nan)
file_excel.iloc[:,[2,3]]=file_excel.iloc[:,[2,3]].abs()
col_list = list(file_excel)
col_list[4], col_list[2] = col_list[2], col_list[4]
file_excel.columns = col_list
Perforation=pd.DataFrame(data=None)
for i in wells:
    well_name=pd.DataFrame({'WELLNAME '+i}, columns=[1])
    Perforation=Perforation.append(well_name)
    Perforation=Perforation.append(file_excel.iloc[:,[1,2,3,4]][file_excel.iloc[:,0]==i])
    Perforation=Perforation.append(pd.Series(dtype = 'object'),     ignore_index=True)

def SaveFile():
    Save=fd.asksaveasfile(mode='w',defaultextension=".ev", initialfile=name)
    Save.write(Perforation.to_string(index=False, header=False, na_rep=' '))
    win.destroy()

win = tk.Tk()
path = resource_path("image.png")
photo = tk.PhotoImage(file=path)
win.iconphoto(False, photo)
win.config(bg='#FFC')
win.title('Конвертация в формат .ev')
win.geometry('400x130+500+500')
win.resizable(False, False)

label_1 = tk.Label(win, text = 'Сохранение:',
                  bg = '#FFC',
                  font=('Arial', 10, 'bold'),
                  padx=20,
                  pady=10).pack()
btn_1 = tk.Button(win, text = 'Сохранить как', 
                 command = SaveFile,
                 activebackground = '#6F6',
                 font=('Arial', 12, 'bold'),
                 padx=20,
                 pady=10,  
                 relief = tk.RAISED,
                 bd=2).pack()
win.mainloop()

file[0]类型

误差屏

EN

回答 1

Stack Overflow用户

发布于 2022-01-21 16:43:32

当我创建虚拟env时,我应该添加openpyxl模块。我做到了,现在一切都很好

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/70785252

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档