[英]Drop rows based on month of year in date column in pandas
我试图在12月,1月和2月删除行。
注意:我将日期设置为索引。
df.drop(df.loc[(df.index.month==12) | (df.index.month==1) | (df.index.month==2)])
您可以使用Series.isin
:
# Boolean indexing.
# df = df.loc[~df.index.month.isin([12, 1, 2]), :] # For a copy.
df = df[~df.index.month.isin([12, 1, 2])]
# Equivalent code using df.drop.
df = df.drop(df.index[df.index.month.isin([12, 1, 2])])
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.