在列中的数字前添加号码

发布于 2025-01-30 03:00:24 字数 259 浏览 1 评论 0 原文

我有这个示例列

year_short
89
99
97
87
98
00
02
05
10
11
20
22

我想做的就是这样

year_long
    1989
    1999
    1997
    1987
    1998
    2000
    2002
    2005
    2010
    2011
    2020
    2022

做这样的列?

I have this example columns

year_short
89
99
97
87
98
00
02
05
10
11
20
22

what I want to do is to make that column into like this

year_long
    1989
    1999
    1997
    1987
    1998
    2000
    2002
    2005
    2010
    2011
    2020
    2022

is it possible to make like that ?

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

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

发布评论

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

评论(2

萌酱 2025-02-06 03:00:24

您可以使用少于25位的任何两个位年属于 2000 Century的逻辑,而任何大于或等于25的值属于 1900 Century:

df["year_long"] = np.where(df["year_short"] < 25, 2000 + df["year_short"], 1900 + df["year_short"])

You could use the logic that any two digit year which is less than 25 belongs to the 2000 century, while any value greater than or equal to 25 belongs to the 1900 century:

df["year_long"] = np.where(df["year_short"] < 25, 2000 + df["year_short"], 1900 + df["year_short"])
生来就爱笑 2025-02-06 03:00:24

道歉,这是针对Excel的,但是数字应该相似,除非它可以帮助他人,否则我会删除。

因此,也许:

=if(A2>22,1900+A2,2000+A2)

您可能想要大于23或30,取决于您的数据。

Apologies, this is for Excel, should be similar in Numbers though, I will delete unless it may help others.

So perhaps:

=if(A2>22,1900+A2,2000+A2)

You may want greater than 23 or 30, depends on your data.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文