nowdate=‘
0 2022-01-01
1 2022-01-02
2 2022-01-03
3 2022-01-04
4 2022-01-05’
想要写出“现在是{}月{}日”
nowdate数据类型是dtype('<M8[ns]')
先看能不能遍历nowdate ,能遍历就好办啦
for n in nowdate:
print(n,type(n))
这样应该可以成功
for n in nowdate:
s = n.strftime('%Y-%m-%d').split("-")
print("现在是{}月{}日".format(s[1],s[2]))
搜字符串截取, list[index1:index2] 这种适合数据格式明确,已知数据位置信息;也可以使用正则表达式;这是取数据的方法,将数据添加到指定位置(就是你输出)涉及到的是字符串格式化。