[英]Passing a pandas dataframe object into a function
I have dataframe objects that I would like to to pass into a function.我有我想传递给函数的数据帧对象。
x = pd.Dataframe()
def function(z):
"code"
return result
result = function(x)
I'm new to python, can someone please steer me in the right direction.我是python的新手,有人可以引导我朝着正确的方向前进。
Below I am showing a simple function that would have the input parameter as a DataFrame object, and it would check if one of the columns has the String "Some", if so, it returns the Boolean results.下面我展示了一个简单的函数,它将输入参数作为一个 DataFrame 对象,它会检查其中一列是否有字符串“Some”,如果有,它返回布尔结果。
Check if this helps.检查这是否有帮助。
x = pd.DataFrame([[1,'Some Text'],[2,'New Text']],columns=('SINO','String_Column'))
def function(z):
l_local_df = z['String_Column'].str.contains('Some')
return l_local_df
result = function(x)
print result
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.