简体   繁体   中英

How can I remove the string annotations and keep the values?

import pandas
import numpy as np
cols = ['DATA']
val = pandas.read_excel('ACC_HAMMER.xlsx' , names = cols)
val.values
main = np.array(val)
print(main)

The output I get is as Follows:

[['0.00000000E+000,3.82345878E-002,1.80000000E+002']
['1.25000000E+000,1.90616930E-001,-6.71922991E+001']
['2.50000000E+000,9.72069843E-002,7.28934980E+001']
 ..., 
['1.27625000E+003,2.19000920E+000,-1.78028307E+002']
['1.27750000E+003,2.22545238E+000,-1.78318835E+002']
['1.27875000E+003,2.20842885E+000,-1.79763405E+002']]

I need to remove the string annotations and sort the data. the first value is x the middle value is a magnitude for y and the last value is a phase. I need the strings removed and 3 lists out.

The excel file has all the values in a single column with a comma seperating them.

The answer is deceptively simple. Python has a function for this. float(yourstring) . You can loop over your list of lists and use split(“,”) to split them on the comma, then loop over the list returned split and pass them to float() and store the returned number in a list.

使用pd.read_csv以CSV pd.read_csv读取它,并指定逗号作为分隔符。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM