[Tutor] Delete unwanted rows

Alexis Prime ap235711 at gmail.com
Wed Apr 9 11:23:09 CEST 2014


My question is whether I should write a loop or a function to delete rows.

I'm using pandas. But you may be able to help me as my question is about
the reasoning behind programming.

I have a pandas dataframe that looks like this, covering all countries in
the world, for over 200 rows and many columns:

Canada                20
China                  112
Germany             10
Japan                  12
Martinique             140
Mexico                180
Saint Kitts            90
Saint Martins        133
Saint Helena         166
USA                    18

# So I write a list of small countries that I wish to exclude from my
analysis. What I want to do is to delete the rows from my dataframe.

    toexclude = ['Martinique', 'Saint Kitts', 'Saint Martins', 'Saint

After this, should I write a loop to loop through the dataframe, find the
countries that I want to delete, and then delete the rows?

Or should I write a function, which deletes those rows, and then returns me
a new and trimmed dataframe?

Thank you for helping me figure this out.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20140409/cde36dea/attachment.html>

More information about the Tutor mailing list