Numpy function to create arrays from tabular data.
Questions tagged [genfromtxt]
287 questions
1
vote
1 answer
when I convert string to integer using numpy genfromtxt function, why is it all 0 for what I want to convert
I should get different number of different materials of wood. but I got 0 for all materials.
%%writefile wood.txt
item,material,number
100,oak,33
110,maple,14
120,oak,7
145,birch,3
tree_to_int = dict(oak=1,maple=2,birch=3)
def convert(s):
…

Peca
- 13
- 2
1
vote
1 answer
Multiplying ndarray with scalar: TypeError: invalid type promotion
I'm trying to multiply every column in an ndarray by a scalar. When I try to do this, I get the error TypeError: invalid type promotion.
I've tried using array.astype(float), but this gives all NaNs.
array = np.genfromtxt("file.csv", dtype=float,…

gilmour
- 23
- 1
- 4
1
vote
3 answers
(Python) Using numpy.genfromtxt for filling list with data (different datatypes)
i have an data.txt like that
16.37.235.153|119.222.242.130|38673|161|17|62|4646|
16.37.235.153|119.222.242.112|56388|161|17|62|4646|
16.37.235.200|16.37.235.153|59009|514|17|143|21271|
I want to get a list with the…

QWERASDFYXCV
- 245
- 1
- 6
- 15
1
vote
2 answers
numPy gives nan while reading a negative number from a file
I tried to read the contents of a 3x3 matrix stored in a text file having the following values.
−30 10 20
10 40 −50
20 −50 −10
I used numpy.genfromtxt as follows but when it gave nan in place of negative data values.
data =…

Ashutosh Kumar
- 109
- 1
- 9
1
vote
2 answers
read specified column from a file which contains multiple sets of data using Python
I am trying to load multiple columns of data from a .txt file using python.
My file contains multiple sets of data, and each set have a title.
I want to choose a set and then choose 2 columns from it.
I am using genfromtxt to read the .txt file,…

Moe
- 13
- 3
1
vote
1 answer
Importing csv embedding special character with numpy genfromtxt
I have a CSV containing special characters. Some cells are arithmetic operations (like "(10/2)").
I would like to import these cells as string in numpy by using np.genfromtxt.
What I notice is that it actually import them in UTF8 (if I understood).…
user330860
1
vote
2 answers
Genfromtext Issues with umlauts
I was just working on a program i made for fun and i came across a problem that i was unable to find a solution to.
The code I wrote looked something like this:
import numpy as np
data= np.genfromtxt('list.txt', unpack=True, dtype=("U12",…

LarsK
- 13
- 3
1
vote
1 answer
How to import arrays from a .txt file to numpy arrays?
Apologies if this is super noob, but I've tried searching all over StackOverflow and cannot find out how to import an array from a text file to a numpy array when there are "[" or "[[" chars already present.
Context: I saved system log output to a…

CodeinCafes
- 107
- 1
- 1
- 8
1
vote
1 answer
numpy read txt error (loadtxt, genfromtxt)
I would like to read text file like below in python
Example of text file
{# "Column 4-5 Quantity": "Re/Im Pressure"
# "Column 4-5 Units": ""
# "Number Rows": 3584879
#}
4.0740740741e-002 -5.0370370370e-002 7.3333333333e-002 …

박태영
- 75
- 6
1
vote
2 answers
Import data from a text file with random missing data in python
I have been trying, unsuccessfuly, to use numpy.genfromtxt() to import the data from a text file into an array.
The problem I have is these data files should have five columns but from time to time a data entry is missing on a line and I only have 4…

Richard
- 63
- 5
1
vote
1 answer
How to properly format a time as loaded from a file with numpy.genfromtxt()?
my code:
def parsetime(v):
return np.datetime64( 'filename.txt',
datetime.datetime.strptime( v, '%H:%M' )
)
hor = np.genfromtxt( 'filename.txt',
skip_header = 3,
…

hawk
- 21
- 4
1
vote
2 answers
how to load a file with date and time as a datetime object in python?
need to load this file with date in first col and HH:MM in second col.
How does it work with a numpy.genfromtxt()? Maybe pandas?
My file looks like:
2017-Feb-11 00:00 m 4.87809 1.86737 5.04236 0.27627 1.5995
2017-Feb-11 00:05 m …

hawk
- 21
- 4
1
vote
1 answer
dtype argument in numpy.genfromtxt
>>> from io import StringIO
>>> import numpy as np
>>> s = StringIO("1,1.3,abcde")
>>> data = np.genfromtxt(s, dtype=[('myint','i8'),('myfloat','f8'),
... ('mystring','S5')], delimiter=",")
>>> data
array((1, 1.3, 'abcde'),
dtype=[('myint',…

Akash Chandra
- 375
- 1
- 4
- 13
1
vote
1 answer
Genfromtxt skips information with #
I have a problem with reading in a CSV file with # signs. The CSV looks like this.
aaa;;xxx;aaa;aaa;aaa;xxx;xxx;xxx;xxx;xxx;xxx;aaa
with aaa as a string and xxx as float. But in this file there is a line like…

Toggo
- 127
- 1
- 7
1
vote
0 answers
Importing a weird text file into a Pandas DataFrame
I'm having a lot of trouble importing a weirdly formatted text file into a Pandas DataFrame—or at all for that matter. Here are the first several lines of the text file:
Name RA Dec B vh sig Type D1 D2
00006-0211…

Bobby Stiller
- 137
- 1
- 1
- 9