【发布时间】:2021-08-04 12:44:33
【问题描述】:
您好,如果此值包含“-”,我正在尝试获取特定列中的前一个值:
这是我的代码:
count=-1
for i, row in df1.iterrows():
count=count + 1
if row["SUBCAPITULO"]== " "and count>0 and "-" in df1.loc[count-1:"SUBCAPITULO"]:
row["SUBCAPITULO"]= df1.loc[count-1:"SUBCAPITULO"]
【问题讨论】:
-
你能用
df1的样本更新你的帖子吗?df1.head()的输出应该足够了。 -
pandas.ffilll ?
-
@woblob。这里不可能立即进行,因为还有第二个条件。可能使用 shift 更合适。