我正在尝试将一些本地函数导入到我的主程序中,如下所示:
class QuestionManager: ObservableObject {
@Published var question: Question
@Published var type: Question.QuestionType
@Published var prompt: String
@Published var options: [String]?
@Published var error: String? = nil
@Published var id = ""
init(_ question: Question) {
self.question = question
self.type = question.type
self.prompt = question.prompt
self.options = question.options
self.id = question.id
}
func saveQuestion() {
self.question.prompt = prompt
self.question.type = type
self.question.options = options
}
func checkQuestion() -> Bool {
if type == .checkbox || type == .multiple {
if options!.count < 2 {
error = "You must have at least two options"
return false
}
else if options!.contains("") {
error = "Options must not be empty"
return false
}
else if !options!.elementsAreUnique() {
error = "Options must be unique"
return false
}
}
if prompt.isEmpty {
error = "You must include a prompt for your question"
return false
}
return true
}
func changeType(_ type: Question.QuestionType) {
if type == .text {
options = nil
}
else {
options = ["Option 1", "Option 2", "Option 3"]
}
self.type = type
}
func addOption() {
guard options != nil else { return }
if options!.count == 5 {
error = "No more than 5 options are permitted"
}
else {
let count = options!.count
let newOption = "Option \(count + 1)"
options!.append(newOption)
}
}
func deleteOption(option: String) {
guard options != nil else { return }
guard let index = self.options!.firstIndex(of: option) else {
self.error = "An error occured during deleting ... sorry you're screwed"
return
}
self.options!.remove(at: index)
}
}
函数“funciones.py”是下一个:
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
from funciones import dumifica
df_orig = pd.read_csv("D:/BMA_TBL_CONSOLIDADO_PYME_FULL_C1_DEV.csv",';')
df_all = df_orig[[a for a in df_orig.columns if a in ('ID_ANO_MES','ID_RUT','CLAS_VAR11','CLAS_VAR9','TIPO_DEU_SBIF_CMF','TIPO_DEU_SBIF12_CMF','TIPO_DEU_SBIF3_CMF','TIPO_DEU_SBIF6_CMF','tip_deudor_12_CMF')]]
df_orig.head()
vars_dum = ['CLAS_VAR11','CLAS_VAR9']
for i in vars_dum:
df_all = dumifica(df_all,i)
程序显示了下一个错误:
NameError: name 'pandas' 未定义
PS:该程序在我将函数包含在同一代码中时没有问题,当我尝试执行外部代码时会出现问题。