根据数据范围分配财政年度

发布于 2025-01-18 00:55:11 字数 558 浏览 0 评论 0原文

我试图根据日期范围分配适当的会计年度。 设置会计年度参数 我的数据框架包含索赔记录,其中每个记录显示“生成的日期”,“索赔金额”和“付款金额”。 dataframe 这些列中每一列的数据类型是:

  • 日期生成= datetime64 [ns](ex:'2018-10-03')
  • 索赔金额= float64(ex:2,948.35)
  • 金额付费= float64(ex:2,948.35),

我想创建根据“生成的日期”将每个记录分类为正确的会计年度的新专栏“财政年度”。

我尝试了使用“ pandas剪切”,“ lambda apply”,“ pandas类别”的各种解决方案,但我一直遇到日期范围条件的问题。有人可以帮我吗?谢谢你!

I am trying to assign the appropriate fiscal year based on date ranges.
set fiscal year parameters
My data frame contains records of claims where each record shows the 'Date Generated' , 'Claim Amount', and 'Amount Paid'.
dataframe
The data types for each of those columns is:

  • Date Generated = datetime64[ns] (ex: '2018-10-03')
  • Claim Amount = float64 (ex: 2,948.35)
  • Amount Paid = float64 (ex: 2,948.35)

I want to create a new column 'Fiscal Year' that classifies each record into the correct fiscal year based on the 'Date Generated'.

I've tried a variety of solutions using 'pandas cut', 'lambda apply', 'pandas category' but I keep running into issues with the date range condition. Can someone help me with this? Thank you!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

痴梦一场 2025-01-25 00:55:11

看起来您的会计年度开始在日历年之前的两个月开始,所以我将在当前日期添加两个月并占用该年度财产

offset = pandas.DateOffset(months=2)
df['Fiscal Year'] = (df['Date Generated'] + pandas.DateOffset(months=2)).dt.year

Looks like your fiscal year begins two months before the calendar year, so I'll add two months to the current date and take the year property

offset = pandas.DateOffset(months=2)
df['Fiscal Year'] = (df['Date Generated'] + pandas.DateOffset(months=2)).dt.year
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文