I have been programming in Java and am trying to learn Python and Graphlab now.
I looked at the Graphlab documentation here but it is insufficient for me to understand how .apply works. There does not seem to be much on Google either.
There are two examples of usage I am trying to figure out:
Where I have a column of country names, and a function to convert "USA" to "United States":
def transform_country(country) if country == 'USA': return 'United States' else: return country
how does the following command / apply work, so that it replaces all instances of "USA" with "United States"? What is .apply doing?
table['Country'] = sf['Country'].apply(transform_country)
In comparison, where I have a column containing a dictionary, say "and" => 5, "stink" => 1, "because = "1", how does .apply work with the function below to display the number associated with "and"?
Function:
def awesome_count(word_count): if 'and' in word_count: return word_count['and'] else: return 0
Command:
products['awesome'] = products['word_count'].apply(awesome_count)