df = rocksfile snapshot of my dataframe
Question: Write a function that will take a row of a DataFrame and print out the song, artist, and whether or not the release date is < 1970.
Defining my function:
def release_info(row):
"""Checks if song is released before or after 1970."""
if rocksfile.loc[row, 'Release_Year'] < 1970:
print str(rocksfile.loc[row,'Song_Clean']) + " by " +
str(rocksfile.loc[row,'Artist_Clean']) \
+ " was released before 1970."
else:
print str(rocksfile.loc[row,'Song_Clean']) + " by " + str(rocksfile.loc[row,'Artist_Clean']) \
+ " was released after 1970."
Using the .apply() function, apply the function you wrote to the first four rows of the DataFrame. You will need to tell the apply function to operate row by row. Setting the keyword argument as axis=1 indicates that the function should be applied to each row individually.
Using .apply:
rocksfile.apply(release_info, axis = 1, row=1)
Error Message:
TypeError Traceback (most recent call last)
<ipython-input-61-fe0405b4d1e8> in <module>()
1 #a = [1]
2
----> 3 rocksfile.apply(release_info, axis = 1, row=1)
TypeError: ("release_info() got multiple values for keyword argument 'row'", u'occurred at index 0')
release_info(1)