我希望按年选择行:
import pandas as pd
import numpy as np
df = pd.DataFrame(columns=['Start','End'],data=[[np.datetime64('2001-01-01'),np.datetime64('2001-07-01')],[np.datetime64('2002-01-01'),np.datetime64('2002-11-01')]])
print(df)
Start End
0 2001-01-01 2001-07-01
1 2002-01-01 2002-11-01
所以我试试:
df_2001 = df.loc[df['Start'.year == 2001)]]
Traceback (most recent call last):
Python Shell, prompt 16, line 1
invalid syntax: <string>, line 1, pos 30
如何在datetime64列中按年份选择?