To drop rows from a pandas DataFrame that have a specific condition on a column, you can use the drop()
method along with boolean indexing.
Here's how you can drop rows where dt.weekday
is equal to 0 in Python:
main.py405 chars18 lines
Output:
main.py100 chars6 lines
In this example, we use the dt.weekday
attribute to get the weekday number (Monday is 0, Tuesday is 1, and so on). We use boolean indexing to select only the rows where dt.weekday
is not equal to 0, which gives us all the rows except those where the weekday is Monday. Finally, we assign the filtered DataFrame back to df
.
gistlibby LogSnag