HI
Do anyone know how to convert element in the list to float, and write them into excel?
My code will read a file and write it into excel, attached picture. But I wish to convert the red mark into float, else in excel it will occur exclamation mark.
I try many methods using the index and split but still not working.
test.txt:
My source code:
Do anyone know how to convert element in the list to float, and write them into excel?
My code will read a file and write it into excel, attached picture. But I wish to convert the red mark into float, else in excel it will occur exclamation mark.
I try many methods using the index and split but still not working.
test.txt:
Quote:=========================UL=========================
datettime ingress-traffic egress-traffic
20230206.160207.082170 0.000000 0.000000
20230206.160212.099560 0.000000 0.000000
20230206.160217.116930 0.000000 0.000000
20230206.160222.135234 0.001146 0.001100
20230206.160227.152599 0.001410 0.001346
My source code:
lists = {} current_key = None with open ('test.txt', 'r')as myfile: readline=myfile.read().splitlines() for line in readline: #print(line) if "=" in line: current_key = line.strip("=") lists[current_key] = [] else: assert current_key is not None # there shouldn't be data before a header lists[current_key].append(line) for i in lists["UL"]: i=i.split(' ') UL.append(i) import pandas as pd df1 = pd.DataFrame(UL) df1 = df1.rename(columns=df1.iloc[0]).drop(df1.index[0]) # To Excel with pd.ExcelWriter('out.xlsx', engine='xlsxwriter') as writer: df1.to_excel(writer, 'sheet1', index=False) worksheet = writer.sheets['sheet1'] #worksheet.autofit() worksheet.set_column(1, 3, 25)Itry using below seems not working. Does anyone have any ideas to convert the last two value into float and wiite into excel with out occurring exclamation mark.
UL =[] #ULindex= lists["UL"][0] #get header title #UL.append(ULindex) ULrest=lists["UL"][1:] ULindex= lists["UL"][0] #print(ULindex) #for i in lists["UL"]: for i in ULrest: datetime=value=i.split(' ')[0] #print(datetime) value=i.split(' ')[1:-1] UL.append(datetime) for ii in value: UL.append(float(ii)) print(UL)