df_dt.dt.weekday和df_dt.weekday()的区别
df_dt.dt.weekday和df_dt.weekday的作用都是一样抽取日期信息。
区别在于处理数据类型不同
df_dt.weekday处理list类型
import pandas as pd
from pandas import to_datetime
#li=["2020/04/22 22:11:20","2020/04/26 22:11:20"]
li="2020/04/26 22:11:20"
df_dt = to_datetime(li, format="%Y/%m/%d %H:%M:%S")
print(df_dt)
y=df_dt.year
s=df_dt.second
m=df_dt.minute
h=df_dt.hour
d=df_dt.day
M=df_dt.month
w=df_dt.weekday() #0-6
print("年:",y)
print("月:",M)
print("日:",d)
print("时:",h)
print("分:",m)
print("秒:",s)
print("周几:",w+1)
结果:
df_dt.dt.weekday,处理Series类型
import pandas as pd
from pandas import