This is in reference to my previous question related to extracting data from .asc file and separating them while having multiple delimiters.
I want to perform mathematical operations on the float elements of the list of lists generated from the above question. The separation of individual data from the string has been achieved however, since the list of lists has also generated individual elements in form of strings i am unable to perform mathematical operations on them.
I would like to be able to access each element in the list of lists, convert them to float type and then perform mathematical operations on them.
Here is my code where in the .asc file strings have been separated into individual elements and stored as list of lists.
This is the image of a specific set of datas i got from the bigger list of lists.
I access the specific set of data from the lists and then when i try to convert them to float, i get this error ValueError: could not convert string to float: '.'
This is the code i have been working with
import numpy as np
import pandas as pd
import re
Output_list = []
Final = []
count = 0
with open(r"myfile.asc","r") as file_in:
for line in map(str.strip, file_in):
if "LoggingString :=" in line:
first_quote = line.index('"') # returns the column number where '"' first appears in the
# whole string
last_quote = line.index('"', first_quote + 1) #returns the column value where " appears last
#in the # whole string ( end of line )
Output_list.append(
line[:first_quote].split(maxsplit=1)
+ line[first_quote + 1: last_quote].split(","),
)
Final.append(Output_list[count][8:25])
Data = list(map(float, Output_list[count][8])) #converting column 8th element of every lists
#in Output_list to float
count += 1
df = pd.DataFrame(Output_list)
df.to_csv("Triall_2.csv", sep=';')
df_1 = pd.DataFrame(Final)
df_1.to_csv("Test.csv", sep=";")
I alternatively tried using np.array(Final).astype(float).tolist() method as well but it didn't change the strings to float as i wanted.


Data = float(Output_list[count][8])?