Desired output has not been posted and the request is unclear.
Taking these comments into account:
- trying to get the previous row value in an specific column if this value contains a dash
- I think OP wants to fill the dash- value over multiple lines
Maybe this helps...
import pandas as pd
df = pd.read_csv('test.csv')
print(df, '\n\n')
'''
Shows:
Other_data SUBCAPITULO
0 qwer NaN
1 vfds NaN
2 sdfg 1.01 – TORRE – 1
3 hfgt NaN
4 jkiu capitulo
5 bvcd 2.01 – TORRE – 1
6 grnc NaN
7 sdfg capitulo
8 poij NaN
9 fghg 2.01 – TORRE – 1
'''
for i in reversed(df.index):
if i >= 1:
if '–' in str(df.loc[i, 'SUBCAPITULO']):
if str(df.loc[i-1, 'SUBCAPITULO']) == 'nan':
df.loc[i-1, 'SUBCAPITULO'] = df.loc[i, 'SUBCAPITULO']
print(df)
'''
Shows:
Other_data SUBCAPITULO
0 qwer 1.01 – TORRE – 1
1 vfds 1.01 – TORRE – 1
2 sdfg 1.01 – TORRE – 1
3 hfgt NaN
4 jkiu capitulo
5 bvcd 2.01 – TORRE – 1
6 grnc NaN
7 sdfg capitulo
8 poij 2.01 – TORRE – 1
9 fghg 2.01 – TORRE – 1
'''
print('\n')