Obviously some of your lines don’t have valid float data, specifically some line have text id
which can’t be converted to float.
When you try it in interactive prompt you are trying only first line, so best way is to print the line where you are getting this error and you will know the wrong line e.g.
#!/usr/bin/python import os,sys from scipy import stats import numpy as np f=open('data2.txt', 'r').readlines() N=len(f)-1 for i in range(0,N): w=f[i].split() l1=w[1:8] l2=w[8:15] try: list1=[float(x) for x in l1] list2=[float(x) for x in l2] except ValueError,e: print "error",e,"on line",i result=stats.ttest_ind(list1,list2) print result[1]
Related Posts:
- Convert bytes to a string
- Replacing instances of a character in a string
- Changing one character in a string
- Converting integer to string in Python
- Reverse a string in Python
- How do I compare two strings in python?
- Python: Converting string into decimal number
- How do I lowercase a string in Python?
- How do you round UP a number?
- How do you round UP a number?
- How do I get a substring of a string in Python?
- Python- Robot Framework Rebot Using List
- Python vs Cpython
- How to read a file line-by-line into a list?
- How can I represent an ‘Enum’ in Python?
- strip(char) on a string
- numpy array: IndexError: too many indices for array
- How do I specify new lines on Python, when writing on files?
- Relative imports – ModuleNotFoundError: No module named x
- bash: pip: command not found
- Using global variables in a function
- How do I check what version of Python is running my script?
- How to convert list to string [duplicate]
- Python for-in loop preceded by a variable
- How do I upgrade the Python installation in Windows 10?
- What does if __name__ == “__main__”: do?
- Difference between del, remove, and pop on lists
- How can I install packages using pip according to the requirements.txt file from a local directory?
- How to measure elapsed time in Python?
- How to uninstall Anaconda completely from macOS
- Python: Start and stop timer [duplicate]
- Selecting multiple columns in a Pandas dataframe
- not all arguments converted during string formatting.. NO % variables
- TypeError: ‘builtin_function_or_method’ object is not subscriptable
- Python Variable Declaration
- Relative imports in Python 3
- ImportError: No module named sklearn.cross_validation
- ImportError: No module named sklearn.cross_validation
- How can I prevent the TypeError: list indices must be integers, not tuple when copying a python list to a numpy array?
- “pip install unroll”: “python setup.py egg_info” failed with error code 1
- Converting string into datetime
- ImportError: No module named matplotlib.pyplot
- How do I install pip on macOS or OS X?
- working of \n in python [duplicate]
- ImportError: No module named matplotlib.pyplot
- How do I list all files of a directory?
- Pip freeze vs. pip list
- Print string to text file
- Accessing the index in ‘for’ loops?
- The difference between comparison to np.nan and isnull()
- How do I append one string to another in Python?
- How can I split and parse a string in Python?
- Limiting floats to two decimal points
- How to read a text file into a string variable and strip newlines?
- Python convert tuple to string
- TypeError: ‘float’ object not iterable
- write() versus writelines() and concatenated strings
- Why is it string.join(list) instead of list.join(string)?
- Why is it string.join(list) instead of list.join(string)?
- How to remove punctuation in python?
- Split string with multiple delimiters in Python [duplicate]
- How to check if the string is empty?
- How to get a random number between a float range?
- How to check whether a str(variable) is empty or not?
- What does the ‘b’ character do in front of a string literal?
- How to add a string in a certain position?
- Remove all special characters, punctuation and spaces from string
- This can be done without regex:
- Pythonic way to create a long multi-line string
- ‘numpy.ndarray’ object has no attribute ‘index’
- Convert hex to binary
- Quoting backslashes in Python string literals
- Python string class like StringBuilder in C#?
- n-grams in python, four, five, six grams?
- Best way to replace multiple characters in a string?
- How do I remove a substring from the end of a string?
- Detect whether a Python string is a number or a letter
- Finding all possible permutations of a given string in python
- How do I append one string to another in Python?
- AttributeError: ‘list’ object has no attribute ‘replace’ when trying to remove character
- AttributeError: ‘list’ object has no attribute ‘replace’ when trying to remove character
- Count the number of occurrences of a character in a string
- How can I find the first occurrence of a sub-string in a python string?
- How to join on multiple columns in Pyspark?
- Replacing a character from a certain index
- Numpy float64 vs Python float
- Easy pretty printing of floats?
- urllib2.HTTPError: HTTP Error 403: Forbidden
- Convert a Unicode string to a string in Python (containing extra symbols)python string unicode type-conversion
- Create nice column output in python
- TypeError: decoding str is not supported
- AttributeError: ‘str’ object has no attribute ‘items’
- How does str(list) work?
- What is the difference between a string and a byte string?
- How to strip a specific word from a string?
- Python cant convert ‘list’ object to str error [closed]
- Using strip() to clean up a string
- Python code to remove HTML tags from a string
- Cannot concatenate ‘str’ and ‘float’ objects?
- How to repeat individual characters in strings in Python