Groups
Sign in
Groups
PyData
Conversations
About
Send feedback
Help
Why is the apply() so slow?
68 views
Skip to first unread message
Junwei Pan
unread,
Jun 9, 2016, 11:18:12 PM
6/9/16
Reply to author
Sign in to reply to author
Forward
Sign in to forward
Delete
You do not have permission to delete messages in this group
Copy link
Report message
Sign in to report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to PyData
Say that we want to convert one column of the dataframe from float type to int type, we can do so in two ways:
1. df['y'] = df['x'].astype(int)
2. df['y'] = df.apply(lambda x : int(x['x'] ), axis=1)
Why is the method 1 mush faster than method 2?
Thx
Pietro Battiston
unread,
Jun 10, 2016, 3:50:41 AM
6/10/16
Reply to author
Sign in to reply to author
Forward
Sign in to forward
Delete
You do not have permission to delete messages in this group
Copy link
Report message
Sign in to report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to pyd...@googlegroups.com
Because in the second you are iterating in Python, which is
inefficient.
http://bfy.tw/6CMk
Pietro
Junwei Pan
unread,
Jun 11, 2016, 12:28:35 PM
6/11/16
Reply to author
Sign in to reply to author
Forward
Sign in to forward
Delete
You do not have permission to delete messages in this group
Copy link
Report message
Sign in to report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to PyData
OK, I see. Thanks a lot.
Reply all
Reply to author
Forward
0 new messages