I have a CSV file in which one column has stored two values at one position such as [345 1234] but sometimes there is no value such as [] or only one [456]. I write a script that works well for empty or single values but it failed for double values. I tried to split, replace space with , but it gave an error because of an empty or single value. How can I include these two values through the loop which can work for both empty and single value?
df file format is as below:
20200423.GS022.mseed_597000,[ ],
20200423.GS022.mseed_600000,[ ],
20200423.GS022.mseed_603000,[424 1901],
20200423.GS022.mseed_606000,[2259],
#code for an empty or single value
with open('myfile.txt','w') as f:
for i in range(len(df)):
itp = df.iloc[i, 1].replace('[', '').replace(']', '')
if itp != '':
P=int(float(itp))/100
else:
P=0
I got this error,
ValueError: could not convert string to float: '424 1901'