All Questions
16 questions
1
vote
2
answers
1k
views
How to convert a String to a float in Python 2.7
I am trying to convert decimal geographic coordinates as strings to a float.
The coordinates are in a csv like this '51213512'. With my Python script I am just reading the coordinates and add the '.'. ...
-1
votes
3
answers
1k
views
Convert given input from string to integer or float in python and if the input is string or character it can able handle it?
inputs: 'aa', '22', '2.45'
input ='22'
try:
print int(input)
except ValueError:
print float(input)
How to handle the above code when the input is 'aa' or 'example'?
1
vote
1
answer
383
views
String that represents float to fraction
Im trying to handle a string like this:
s = '1/2.05'
When I try to parse it into a Fraction:
Fraction(s)
I am obtaining:
ValueError: ("Invalid literal for Fraction: u'1/2.05'", u'occurred at index ...
0
votes
1
answer
27
views
Convert a list of a list of strings with decimals into floats
I have a list of a list that goes like this:
Main_List: [ ['1.2','3.5'],[ ['5.8','8.3'] ]
I am trying to convert one of the sublists into floats, here is what i did:
Main_List[1] = [float(i) for i ...
0
votes
0
answers
137
views
Can't load text from Python numpy for list string
I cant load text using numpy.loadtxt for the list of string inside 'file.dat':
['3317121918', '69', '1345', '15']
['3317122000', '72', '1337', '20']
['3317122006', '75', '1330', '20']
['3317122012'...
2
votes
7
answers
6k
views
Python - delete strings that are float numbers
I have a file with lots of lines that contain numbers seperated by coma , on each line.
Some lines contain numbers that are float numbers ie: ['9.3']
i have been trying to delete those numbers from ...
2
votes
2
answers
2k
views
How does Python determine whether to represent a number using scientific notation or not?
Here are some numbers entered in the Python console, and the resulting representations:
>>> 1
1
>>> 1.234
1.234
>>> 1.234e5
123400.0
>>> 1.234e15
1234000000000000....
0
votes
1
answer
360
views
How to extract a float number from string using loop [python]
I use this loop to extract integers, what changes should I make to this loop which will accept decimal numbers.
Here inputn is a string:
def numberseeker():
global i, inputn, number, num
while i <...
0
votes
2
answers
2k
views
Extract data from string in python
I have a .csv file with data constructed as [datetime, "(data1, data2)"] in rows and I have managed to import the data into python as time and temp, the problem I am facing is how do I seperate the ...
0
votes
2
answers
653
views
python 2.7 storing a float and a string from the same raw_input line [closed]
I am trying to get python 2.7 to store a single line of input that contains both a string and three float numbers so that I can perform some averages, etc.
ex. input: Tom 25 30 20
I tried:
name, ...
1
vote
3
answers
277
views
Convert "numeric" string into some number type in Python without lose information
I'm creating a composite string for memorize id and sub id like this:
1.1
1.2
1.3
in this way:
main_id=1 #not related to sub_id
sub_id= 1 #or more by increment
item = str(main_id)+"."+str(...
2
votes
1
answer
32
views
Skipping over array elements of certain types
I have a csv file that gets read into my code where arrays are generated out of each row of the file. I want to ignore all the array elements with letters in them and only worry about changing the ...
0
votes
2
answers
4k
views
ValueError: could not convert string to float in simple code
# -*- coding: cp1250 -*-
print ('euklides alpha 1.0')
a = raw_input('podaj liczbę A : ')
b = raw_input('podaj liczbę B : ')
a = float('a')
b = float('b')
if 'a'=='b':
print 'a'
elif 'a' > '...
0
votes
1
answer
3k
views
ValueError: could not convert string to float:
I have a problem with the following code:
inputf = open('test.dat', 'r')
lines = inputf.readlines()
rico_clus_e = []
for line in lines:
line.split()
print line
if (line[0] != '#'):
...
4
votes
5
answers
7k
views
in Python, how to convert list of float numbers to string with certain format?
I have a list of tuple of float numbers, something like
[ (1.00000001, 349183.1430, 2148.12222222222222), ( , , ), ..., ( , ,) ]
How can I convert all numbers to strings, with same format (scientific ...