Reputation: 19164
I have a df
and in iteration with print statement,
print(df.iloc[i])
I am getting value as
But how to get the index value of it which is a date from df.iloc[i]?
Upvotes: 0
Views: 1052
Reputation: 972
We have to reset the index since can't perform transformations on the index afaik.
New date column looks like datetime object so we have to import it.
The code below would create a new column with only the year-month-day in a new column. You can always drop the old date column later.
import datetime as dt
df.reset_index()
df['Y-M-D-Only'] = df['Date'].dt.date
for i in df['Y-M-D-Only']:
print(i)
Upvotes: 0
Reputation: 181
df.iloc[i].name
should give you the index for that particular row.
Upvotes: 3