调用另一个函数到另一个pandas数据框架文件



我有两个脚本:File1.py和file2.py

file1.py

## file1.py
from file2 import *
class df_read():
def __init__(self):
self.df1 = df1
self.df2 = df2
def df1_read(self,fileloc,sheet_NAME):
self.df1 = pd.read_excel(file_loc,sheet_name=sheet_NAME)
self.start_time1 = df1.iloc[0][1]
return self.start_time1
def df2_read(self,file loc,sheet_NAME):
self.df2 = pd.read_excel(file_loc,sheet_name=sheet_NAME)
self.start_time2 = df2.iloc[0][1]
return self.start_time2

file2.py


##file2.py
from file1 import *
result1 = df_read.df1_read(C:Usersexam1.xlsx,'01') - df_read.df2_read(C:Usersexam1.xlsx,'02')
result2 = df_read.df1_read(C:Usersexam2.xlsx,'01') - df_read.df2_read(C:Usersexam2.xlsx,'02')

我想从另一个文件调用一个函数,但它不起作用。你能帮帮我吗?

您没有在第二个代码片段中实例化您的类:

df_obj = df_read()
result1 = df_obj .df1_read(C:Usersexam1.xlsx,'01') - df_obj.df2_read(C:Usersexam1.xlsx,'02')
result2 = df_obj.df1_read(C:Usersexam2.xlsx,'01') - df_obj.df2_read(C:Usersexam2.xlsx,'02')

相关内容

  • 没有找到相关文章

最新更新