[英]Define a main function in python which can run other functions in python
I have a file1.py
file which has a function. 我有一个具有功能的
file1.py
文件。
def func1(x):
....
....
....
return x
I also have a dataframe df
. 我也有一个数据框
df
。
I am running this function using .apply function
我正在使用
.apply function
运行此.apply function
df['col1'].apply(func1)
but for that I have to open the .py
file and run it. 但是为此,我必须打开
.py
文件并运行它。
I want to run .py
file from command line, such that it directly goes to df['col1'].apply(func1)
我想从命令行运行
.py
文件,以便直接进入df['col1'].apply(func1)
So I wanted to define a main function which will run my df['col1'].apply(func1)
所以我想定义一个主函数,它将运行我的
df['col1'].apply(func1)
My knowledge to python is very limited, is there any way to do it? 我对python的了解非常有限,有什么办法吗?
You can put it like this in file1.py
: 您可以将其放在
file1.py
:
import pandas as pd
df = pd.DataFrame([1, 2, 3, 4, 5, 6, 7])
def func1(x):
x = x * 2
return x
print df.apply(func1)
Then run from the command line: 然后从命令行运行:
python file1.py
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.