在Python中的DataFrame中选择具有特定工作日的行 [英] Selecting rows with a certain weekday in DataFrame in Python

查看:134
本文介绍了在Python中的DataFrame中选择具有特定工作日的行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带有时间索引的DataFrame,如:

I have a DataFrame with time index like:

df.index = [2013-09-09 06:23:18, 2013-09-10 07:09:05, ..., 2014-02-02 06:04:04]

如何在某些工作日(如星期一)中选择行?然后,我将在其他工作日没有行.任何帮助表示赞赏.

How could I choose rows in certain weekday, like Monday? Then I won't have the rows in other weekdays. Any help appreciated.

推荐答案

您可以通过df.index.weekday获取工作日,请注意Monday = 0Sunday = 6

You can get the weekday by df.index.weekday, note that Monday = 0 and Sunday = 6

要选择星期一的行,您可以

To select the rows on Monday, you can do

df = df[df.index.weekday==0]

这篇关于在Python中的DataFrame中选择具有特定工作日的行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆