如何将Python代码插入另一个文件上的函数中?

发布于 2025-02-14 01:51:59 字数 859 浏览 2 评论 0原文

晚上好,我一直在研究一些自动化软件,并且遇到了一些障碍,因此我需要从旧数据框架中创建一个数据框架。但是,我的问题是self.new_df行需要进入单独的文件。这些线的数量需要模块化,并根据情况而变化。示例:

file_1


class mapping: 
   __def__(self,new_df,df)):
      xxxxxxxxxxxxxxxx
   
   def map_df():
      self.new_df['column1'] = ''
      self.new_df['column2'] = self.df['column2b']
      self.new_df['column3'] = VARIABLE_ONE 

需要变成:

file_1


import file_2 as f2

class mapping: 
   __def__(self,new_df,df,block_quote):
      xxxxxxxxxxxxxxxxx

   def map_df():
      f2.block_quote

file_2


block_quote =       
      self.new_df['column1'] = ''
      self.new_df['column2'] = self.df['column2b']
      self.new_df['column3'] = VARIABLE_ONE 

长篇小说,我是唯一一个知道python的人,所以我们需要一个文件才能保持不变,而另一个文件只是存储变量,词典以及偶尔的函数,以便容易适用于没有Python经验的人可以更新映射。感谢您的帮助!

Good evening, I've been working on some automation software and I have hit a little snag, so I need to create a dataframe from an old dataframe. However, my problem is that the self.new_df lines need to go into a separate file. The number of these lines needs to be modular and change depending on circumstance. example:

file_1


class mapping: 
   __def__(self,new_df,df)):
      xxxxxxxxxxxxxxxx
   
   def map_df():
      self.new_df['column1'] = ''
      self.new_df['column2'] = self.df['column2b']
      self.new_df['column3'] = VARIABLE_ONE 

Needs to turn into:

file_1


import file_2 as f2

class mapping: 
   __def__(self,new_df,df,block_quote):
      xxxxxxxxxxxxxxxxx

   def map_df():
      f2.block_quote

file_2


block_quote =       
      self.new_df['column1'] = ''
      self.new_df['column2'] = self.df['column2b']
      self.new_df['column3'] = VARIABLE_ONE 

Long story short, I am the only one who knows python so we need one file to remain untouched and another just to store variables, dictionaries, and perhaps the occasional function so that it is easy for someone without python experience could update the mappings. Thanks for any help!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

凝望流年 2025-02-21 01:52:00

尝试执行

from file_2 import block_quote
class mapping: 
   __def__(self,new_df,df,block_quote):
      xxxxxxxxxxxxxxxxx

   def map_df():
      f2=block_quote(new_df, df)

#file_2
def block_quote(new_df, df):
       
      new_df['column1'] = ''
      new_df['column2'] = self.df['column2b']
      new_df['column3'] = VARIABLE_ONE 
      return new_df

或生成功能t

Try doing

from file_2 import block_quote
class mapping: 
   __def__(self,new_df,df,block_quote):
      xxxxxxxxxxxxxxxxx

   def map_df():
      f2=block_quote(new_df, df)

#file_2
def block_quote(new_df, df):
       
      new_df['column1'] = ''
      new_df['column2'] = self.df['column2b']
      new_df['column3'] = VARIABLE_ONE 
      return new_df

or generate a function t

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文