Reputation: 1040
I have a DataFrame
object named df
, and I want to generate a list of properly formatted dates. (datetime
module is properly imported)
I wrote:
dates = [datetime.date(df.at(index, "year"), df.at(index, "month"), df.at(index, "day")) for index in df.index]
which gives the error in the title.
If it helps, this is the value of df.head()
:
year month day smoothed trend
0 2011 1 1 391.26 389.76
1 2011 1 2 391.29 389.77
2 2011 1 3 391.33 389.78
3 2011 1 4 391.36 389.78
4 2011 1 5 391.39 389.79
(This is new to me, so I have likely misinterpreted the docs)
Upvotes: 5
Views: 13111
Reputation: 18315
df.at
is not a callable but a property that supports indexing. So change parantheses to square brackets around it:
df.at[index, "year"]
i.e., (
to [
and similar for closing.
Upvotes: 10
Reputation: 1028
Apart from using [
instead of (
you can achieve your goal simply by
pd.to_datetime(df[['year', 'month', 'day']])
Upvotes: 1