简体   繁体   English

如何在python中制作带有日期范围标签工作日和周末(可按日期联接)的表?

[英]How can I make a table with a date range labeling weekdays and weekends (joinable by date) in python?

I've never worked with DataTimeIndex. 我从未使用过DataTimeIndex。 It's giving me a headache as everything I normally would try is not working. 我通常会尝试的所有方法都无法正常工作,这让我头疼。 I've tried converting to datetime and I'm still unable to just make a weekday column using date.weekday or .dayofweek. 我尝试转换为日期时间,但仍然无法仅使用date.weekday或.dayofweek来创建一个工作日列。 Can someone please assist? 有人可以帮忙吗?

date_list = pd.date_range(trainset['date'].min(), trainset['date'].max(), freq='d', name='date_val')


date_list['date_val'] = date_list['date_val'].dt.date
date_list['Weekdays'] = date_list.date_val.dt.dayofweek()

I converted to dataframe and then reset the index because that was what was making it hard for me. 我转换为数据框,然后重置索引,因为那让我很难。 If someone has a solution for how to do it with indexes, please do let me know. 如果有人对如何使用索引有解决方案,请告诉我。 I'll read up on them in the mean time. 同时,我会仔细阅读它们。 thanks. 谢谢。

date_list = pd.DataFrame(pd.date_range(trainset['date'].min(), trainset['date'].max(), freq='d', name='date_val'))

date_list = date_list.reset_index()
date_list['Weekdays'] = date_list.date_val.dt.dayofweek()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何只打印工作日的日期(而不是周末),按日期打印几天范围内的日期? - How to print dates of weekdays only (not weekends) for a range of days by date, for a range of months? Python将int添加到日期,并且仅返回工作日日期,而忽略周末 - Python add int to a date and only return weekdays date ignoring weekends 如何在 python 的日期范围内获取某些特定工作日的列表 - How to get a list of some specific weekdays within a date range in python python 如何从开始日期获取日期 + 不包括周末的天数 - python how to get date from a start date + no of days excluding weekends 如何在 Python 中创建日期范围并转换为 DataFrame - How to make a Date Range in Python and convert into DataFrame Select 在 python 中按 weekday() 的周末和工作日 - Select weekends and weekdays by weekday() in python 如何使日期仅显示一个月的周末(周六和周日)? - how to make date only show weekends (saturday and sunday) for a month? 如何从今天起检索日期,不包括带有日期时间的周末或 Python 中的 pandas - How to retrieve the date from today excluding weekends with datetime or pandas in Python 如何使日期和时间成为python截取的屏幕截图的名称? - How can I make the date and time the name of a screenshot taken by python? 返回特定日期的工作日数(Python) - Return number of weekdays for a specific date (Python)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM