Obabs
Obabs

Reputation: 87

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.

Upvotes: 1

Views: 15716

Answers (1)

pmaniyan
pmaniyan

Reputation: 1046

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.

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

Upvotes: 8

Related Questions