Python 3.x 系列。替换不使用适用于熊猫的正则表达式>;1.0.5

Python 3.x 系列。替换不使用适用于熊猫的正则表达式>;1.0.5,python-3.x,pandas,dataframe,Python 3.x,Pandas,Dataframe,我正在尝试使用下一个代码,以便将索引列的日期部分替换为某个日期的值: input\u dict={ “2019-08-08 | some_col1”:{“some_date”:“2019-08-18”}, “2019-08-09 | some_col2”:{“some_date”:“2019-08-19”}, “2019-08-10 | some_col3”:{“some_date”:“2019-08-20”} } df=pd.DataFrame.from_dict(输入_dict,orient

我正在尝试使用下一个代码,以便将
索引
列的日期部分替换为
某个日期的值

input\u dict={
“2019-08-08 | some_col1”:{“some_date”:“2019-08-18”},
“2019-08-09 | some_col2”:{“some_date”:“2019-08-19”},
“2019-08-10 | some_col3”:{“some_date”:“2019-08-20”}
}
df=pd.DataFrame.from_dict(输入_dict,orient='index')
df.reset_索引(原地=真)
df['index'].replace(to_replace=r“\d{4}-\d{2}-\d{2}”,value=df['some_date'],regex=True,inplace=True)
预期产出:

                  index   some_date
0  2019-08-18|some_col1  2019-08-18
1  2019-08-19|some_col2  2019-08-19
2  2019-08-20|some_col3  2019-08-20
该代码适用于版本备选方案:

df["index"] = df.apply(lambda sr: re.sub(r'\d{4}-\d{2}-\d{2}', sr["some_date"],
                                         sr["index"]), axis="columns")
df["index"] = df.apply(lambda sr: re.sub(r'\d{4}-\d{2}-\d{2}', sr["some_date"],
                                         sr["index"]), axis="columns")
>>> df
0    2019-08-18|some_col1
1    2019-08-19|some_col2
2    2019-08-20|some_col3
dtype: object