'search inbetween text in file -python
How to select and append only Filename D170322.H0 with status sucess, in the file name till D same fixed letters no change and after D"current date".H0 .
we need to fetch file currentdate with "TRANNSS.FTRNONO.VCA579.D+"current_date".H0
Targetid Filename Date STATUS
1234 TRANNSS.FTRNONO.VCA579.D170322.H034367 17-03-2022 SUCESS
1234 TRANNSS.FTRNONO.VCA579.D170322.H134367 17-03-2022 SUCESS
1234 TRANNSS.FTRNONO.VCA579.D170322.H034367 17-03-2022 ERROR
expected output :
Targetid Filename Date STATUS
1234 TRANNSS.FTRNONO.VCA579.D170322.H034367 17-03-2022 SUCESS
daily date change in file name ,below is the file format
today(mar-17) = TRANNSS.FTRNONO.VCA579.D170322.H034367 -
daily date upate in after D (date) == D170322 ,
tomorrow(mar-18) = TRANNSS.FTRNONO.VCA579.D180322.H034369
Solution 1:[1]
Use boolean mask:
today = pd.Timestamp.today().strftime('%d%m%y')
today = f'TRANNSS.FTRNONO.VCA579.D{today}.H034367'
m = (df['Filename'] == today) & (df['STATUS'] == 'SUCESS')
out = df.loc[m]
print(out)
# Output
Targetid Filename Date STATUS
0 1234 TRANNSS.FTRNONO.VCA579.D170322.H034367 17-03-2022 SUCESS
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Corralien |