Questions tagged [genfromtxt]

Numpy function to create arrays from tabular data.

References

287 questions
0
votes
1 answer

numpy genfromtxt - infer column header if headers not provided

I understand that with genfromtxt, the defaultfmt parameter can be used to infer default column names, which is useful if column names are not in input data. And defaultfmt, if not provided, is defaulted to f%i. E.g. >>> data = StringIO("1 2 3\n 4 5…
user3240688
  • 1,188
  • 3
  • 13
  • 34
0
votes
3 answers

reading a table that might have a single row or column (python)

I'm using genfromtxt to extract a table from a csv file: myTable = numpy.genfromtxt("myFile.csv", skip_header=1, delimiter=",", dtype=float) I don't know in advance the size of the table and it may contain a single row or a single column. I expect…
Shaharg
  • 971
  • 1
  • 11
  • 26
0
votes
1 answer

how to load np.array from text file using np.genfromtxt

The file has the following structure: h w P1,1_r P1,1_g P1,1_b P1,2_r P1,2_g P1,2_b ... P1,w_r P1,w_g P1,w_b P2,1_r P2,1_g P2,1_b ... Ph,w_r Ph,w_g Ph,w_b The first line contains one integer, h, which is the height of the image. The second…
0
votes
3 answers

How do i convert one column from an imported csv using numpy from string to float?

I have two csv files which i have imported to python using numpy. the data has 2 columns: [['month' 'total_rainfall'] ['1982-01' '107.1'] ['1982-02' '27.8'] ['1982-03' '160.8'] ['1982-04' '157'] ['1982-05' '102.2'] I…
Yihui
  • 1
0
votes
2 answers

Numpy: Read in an arbitrary number of .txt files and save the data in one numpy array

Excuse me if this has been asked previously, I could not find anything. I am trying to define a function that takes an arbitrary number of .txt files that look like these reads them, concatenates all the rows and saves it into one numpy array. This…
Wulfram
  • 133
  • 5
0
votes
1 answer

ValueError with np.genfromtext

I used np.genfromtxt to load a txt file. Below is the code datasets = np.genfromtxt('X&YTrainingsets1.txt',delimiter="") It happens that I got an error ValueError: Some errors were detected ! Line #1162 (got 5 columns instead of 7) Line…
0
votes
1 answer

How do I use numpy genfromtxt to read a fixed width, mixed format file?

A sample of my data file is below. Note that I have not included all of the header. Note also that often a specific data value is left blank (in this case CALL for rows 1 and 5 but it can be other columns too). USAF WBAN STATION NAME …
twhawk
  • 5
  • 3
0
votes
1 answer

Reading in ASCII file with uncommon formatting in Python

I've never worked with importing data from an ASCII file and I've noticed that different ASCII files have different formats so trying to find a general solution that works for any format has proven challenging for me. I have a .dat (ASCII) file…
Natasha
  • 101
  • 1
  • 12
0
votes
1 answer

How to convert 1D numpy array (made using .genfromtxt() method) to a 2D array?

I am new to numpy and I am trying to generate an array from a CSV file. I was informed that the .genfromtxt method works well in generating an array and automatically detecting and ascribing dtypes. The formula seemingly did this without flaws until…
0
votes
0 answers

numpy genfromtxt loading file with leading column?

I'm trying to extract data from a file that has columns with two different sizes. One of size 1, the other size 6. Unfortunately, I can't find a delimiter that works. The columns are not evenly spaced and neither are they the same size. Example…
0
votes
1 answer

How to extract data from csv by column header

I have csv files (tab separated) that I want to analyse and graph. I can extract the data from the files but I would prefer to do it by using a column header name rather than normal indexing. i.e instead of: freq_data = my_data[:,0] i would use…
Windy71
  • 851
  • 1
  • 9
  • 30
0
votes
1 answer

np.genfromtxt returns a list, not an array

I'm using np.genfromtxt() to read a series of comma delimited text files and load into NumPy arrays for downstream processing (and eventually writing to HDF5). The code works fine (returns an array) when there are 4 (or more) lines (1 header, 2+…
kcw78
  • 7,131
  • 3
  • 12
  • 44
0
votes
2 answers

Why do I keep getting a nan set when coding?

I am trying to convert my csv file into a numpy array so I can manipulate the numbers and then graph them. I printed my csv file and got: ra dec 0 15:09:11.8 -34:13:44.9 1 09:19:46.8 +33:44:58.452 2 …
0
votes
2 answers

numpy.genfromtxt , are uneven spaces between columns causing dtype errors?

The data I'm working with can be found at this gist, And looks like: 07-11-2018 18:34:35 -2.001 5571.036 -1.987 07-11-2018 18:34:50 -1.999 5570.916 -1.988 image of code and output in Jupyter Notebook When calling TB_CAL_array =…
Sarah
  • 3
  • 1
0
votes
2 answers

Print summed arrays when importing files from numpy.genfromtxt

I have several files where the first column is text and the rest numbers like first.txt A 1 3 5 7 B 9 11 13 15 second.txt A 0 4 6 8 B 10 12 14 16 which I import like a=[] b=[] descr=[] descr.append( np.genfromtxt('first_file.txt',…
Alex
  • 191
  • 1
  • 9