Questions tagged [genfromtxt]

Numpy function to create arrays from tabular data.

References

287 questions
2
votes
2 answers

How to force numpy.genfromtxt to generate a non-structured numpy array?

In Python 3 I do: s = StringIO(u"1,1.3,abcde\n2,1.3,test") data = numpy.genfromtxt(s, dtype=[int,float,'U10'], delimiter=',', names=None) and I get: array([(1, 1.3, 'abcde'), (2, 1.3, 'test')], dtype=[('f0', '
dr.doom
  • 480
  • 1
  • 6
  • 17
2
votes
1 answer

NumPy: using loadtxt or genfromtxt to read a ragged structure

I need to read an ASCII file into Python, where an excerpt of the file looks like this: E M S T N... ... 9998 1 1 128 10097 10098 10199 10198 20298 20299 20400 20399 9999 1 1 128 10098 10099 10200 10199 20299 20300 20401 20400 10000 1 1 128…
Mike T
  • 41,085
  • 18
  • 152
  • 203
2
votes
1 answer

recfromcsv, genfromtxt, recfromtxt mysteriously missing from numpy

I am used to using numpy.recfromcsv to load csv files as record arrays in python. However on my new laptop (MB pro running OS 10.6.6), numpy doesn't seem to recognize recfromcsv as a function (same with genfromtxt or recfromtxt). >>> import numpy as…
Tim
  • 21
  • 1
  • 2
2
votes
1 answer

Saving header from CSV file using `numpy.genfromtxt()`

I'm using numpy.genfromtxt() to read in a CSV file, and I'd like to save the header separately from the data below the header. I know that the skip_header=1 parameter allows me to skip the header, but, in that case, the header is lost, but I'd like…
Data2Dollars
  • 731
  • 2
  • 8
  • 21
2
votes
2 answers

importing function parameters numpy

I am trying to import a text file (.xyz), this file looks something like this: 1 9 1 6 "Thu Feb 13 13:12:30 2014 " 0 0 0 0 0 0 38 38 915 915 "CJE " "2 …
Lpng
  • 109
  • 1
  • 8
2
votes
2 answers

error only for one column by using Genfromtxt. All other columns could be read. how can i fix it?

I am new with python and I want to read my data from a .txt file. There are except of the header only floats. I have 6 columns and very much rows. To read it, I'm using genfromtxt. If I want to read the first two columns it's working, but if i want…
Dark
  • 179
  • 2
  • 12
2
votes
2 answers

Read structured data with start/end tags

I have a data file portions of which look like START vertex 266.36 234.594 14.6145 vertex 268.582 234.968 15.6956 vertex 267.689 232.646 15.7283 END START vertex 166.36 23.594 4.6145 vertex 8.582 23.968 5.6956 vertex 67.689 32.646 1.7283 END #…
Nico Schlömer
  • 53,797
  • 27
  • 201
  • 249
2
votes
2 answers

how to import list of list of dictionaries as numpy array

I have a list of list of dictionaries of the following form: [[{'x': 33, 'y': 69, 'z': 870}, {'x': 33, 'y': 69, 'z': 870}],[{'x': 33, 'y': 64, 'z': 876}]] This data is present as a .csv file. I need to import this into Python as a NumPy array.…
2
votes
1 answer

numpy.genfromtxt give nan for complex numbers with minus signs?

I have some complex numbers in a file, written by np.savetxt(): (8.67272e-09+-1.64817e-07j) (2.31263e-08+1.11916e-07j) (9.73642e-08+-7.98195e-08j) (1.05448e-07+7.00151e-08j) This is in a file "test.txt". when I use `np.genfromtxt('test.txt',…
Alex
  • 912
  • 2
  • 7
  • 19
2
votes
1 answer

What is the difference between and array containing dot after the number e.g. [ 1. 2. ] and an array without dot e.g. [ 1 2 ]?

I'm trying to import data from csv file and I get two different types of arrays when I use pandas' read function and numpy's getfromtxt resulting in two different arrays: [[ 1. 0. 1. ..., 1. 0. 0.] [ 0. 1. 1. ..., 1. 0. 0.] [ 0. 1. 1.…
Rafael Lee
  • 43
  • 1
  • 3
2
votes
1 answer

genfromtxt different datatypes

I am trying to import data from a text file with varying number of columns. I know that the first column will always be an int and subsequent cols will be floats in all files. How can I specify this explicitly using…
Ben Howey
  • 33
  • 3
2
votes
0 answers

numpy.genfromtxt does not read data correctly when there is '#' hashtag

This is my fixed width file SNO,NAME,AGE 1abc@-+ 18 2def_= 22 3ghi${ 22 2jkl%] 22 1mn#o 50 3pqr() 14 5stu? 18 6!`$%^&*(20 when i try to read it from numpy.genfromtxt, i get +---+--------+---+ |SNO| NAME|AGE| +---+--------+---+ | …
2
votes
3 answers

Iterate through multiple CSV's checking for an integer value in each file

I am new to python and can use any help I can get. I am on a win7 machine and am using python 3.5 (anaconda) I am trying to iterate through multiple CSV files (10k +) within a folder, checking for any value within that file that exceeds a predefined…
StelioK
  • 1,771
  • 1
  • 11
  • 21
2
votes
1 answer

ValueError: Setting void-array with object members using buffer. Plotting a timeseries of an numpy array

I have 2 numpy arrays with (time and date), and the third with rain. At the end I would like to plot all the info at a xy-plot with matplotlib! This i what I got so far import os import time from datetime import datetime import time import numpy as…
Markus
  • 189
  • 1
  • 1
  • 10
2
votes
1 answer

Manipulating a numpy array

I currently have a csv file with approximately 350 lines and 50 columns, of which I want to access four columns. Using genfromtxt, I'm able to do this. Once I have those columns, however, I want to add a new column based off of the existing columns…
Red Icing
  • 37
  • 2
  • 9