May-22-2020, 09:32 AM
(This post was last modified: May-22-2020, 09:33 AM by player1681.)
After reading a text file, as a column, I want to convert it from string to float; however, an error appears:
I am attaching the text file just in case someone wants to take a look
Regads.
with open('posx_mean_no_acoplo_tf_multiple.txt', 'r') as f2: data = f2.read() print(data) data2=float(data) print(type(data2))
Error:ValueError: could not convert string to float: '2.25\n2.2695317544146922\n2.329339980428795\n2.4250625977456477\n2.5550797011698574\n2.71230173494984\n2.892967911772487\n3.0882634980597587\n3.293449789010904\n3.499272226187544\n3.701367185950187\n3.8913688480023603\n4.06653899594117\n4.220488053299581\n4.352979510931954\n4.460201719579866\n4.544721596733528\n4.605268242898987\n4.646847484315852\n4.670027623810766\n4.681257982348112\n4.681695512358507\n4.677770394738662\n4.669669116126706\n4.662148945229584\n4.6528774839607685\n4.643437850311123\n4.627777953202297\n4.603297500355522\n4.559669579586145\n4.489849558288886\n4.3795396286131405\n4.217820145014248\n3.9876937422929313\n3.675387059204849\n3.26353914389145\n2.733307933151497\n2.105160523649151\n1.5523910517699886\n1.1343162024113826\n0.8156488225000131\n0.5800645817088685\n0.4070368727014218\n0.2831923612679096\n0.19580025579018923\n0.13524269458388608\n0.09417950763477065\n0.06624645771006422\n0.04785919913604819\n0.03502215581410664\n0.026570015997405754\n0.020000851026048753\n0.015528673303797499\n0.011462300535368213\n0.008669991732948468\n0.005840011599713111\n0.004051213365511311\n0.002171916538622823\n0.0012444675811206312\n0.00027638904919229313\n4.4864963753136085e-38\n'
Can anybody help me?I am attaching the text file just in case someone wants to take a look
Regads.
Attached Files