[英]Pandas: Get datetime index value from row
I have a dataframe with datetime type column set to index. 我有一个日期时间类型列设置为索引的数据框。 I want to process the data per row with apply function. 我想使用apply函数处理每行数据。 how can I access the index value of the current row? 如何访问当前行的索引值?
hid lat lon
2016-08-11 10:56:00 549 40.639504 -79.996961
2016-08-11 10:57:00 639 40.539504 -79.993981
2016-08-11 10:58:00 749 40.438842 -79.924733
def f(row):
# I want to access row idx value here
df['new'] = df.apply(lambda row: f(row), axis=1)
由于apply将返回一个Series,因此您可以调用该Series的名称,该名称表示具有以下内容的索引:
df['new'] = df.apply(lambda row: row.name, axis=1)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.