Loading data files: Difference between revisions

From SweepMe! Wiki
Jump to navigation Jump to search
No edit summary
Line 9: Line 9:
{{syntaxhighlight|lang=python|code=
{{syntaxhighlight|lang=python|code=
import numpy as np  # loading numpy package
import numpy as np  # loading numpy package
  data =  np.genfromtxt("mydata.txt", usecols = (0,2,3), skip_header = 4, missing_values = "--", filling_values = float("nan"))
 
  # this example loads data from the first, the third, and the fourth column, it skips the header and replaces missing values by nan (= "not a number")
data =  np.genfromtxt("mydata.txt", usecols = (0,2,3), skip_header = 4, missing_values = "--", filling_values = float("nan"))
  # Load all columns be removing the usecols argument
# this example loads data from the first, the third, and the fourth column, it skips the header and replaces missing values by nan (= "not a number")
# Load all columns be removing the usecols argument
}}
}}


Line 21: Line 22:
{{syntaxhighlight|lang=python|code=
{{syntaxhighlight|lang=python|code=
import numpy as np  # loading numpy package
import numpy as np  # loading numpy package
  data =  np.loadtxt("mydata.txt", usecols = (1,4,5), skiprows=4, delimiter="\t")
 
  # this example loads data from the second, the fifth, and the sixth column and skips the header
data =  np.loadtxt("mydata.txt", usecols = (1,4,5), skiprows=4, delimiter="\t")
  # Load all columns be removing the usecols argument
# this example loads data from the second, the fifth, and the sixth column and skips the header
# Load all columns be removing the usecols argument
}}
}}



Revision as of 14:28, 11 January 2018

Origin

Just drag and drop the saved data files into Origin and select standard Ascii-import. Long name, unit and comment are automatically filled with the three header lines.

Python

The data files can easily be loaded using the numpy package:

import numpy as np  # loading numpy package

data =  np.genfromtxt("mydata.txt", usecols = (0,2,3), skip_header = 4, missing_values = "--", filling_values = float("nan"))
# this example loads data from the first, the third, and the fourth column, it skips the header and replaces missing values by nan (= "not a number")
# Load all columns be removing the usecols argument

Please find all options here: https://docs.scipy.org/doc/numpy-1.13.0/reference/generated/numpy.genfromtxt.html

A faster import can be realized by using the numpy function loadtxt. However, you have to make sure that all characters are numbers and can be converted to floats.

import numpy as np  # loading numpy package

data =  np.loadtxt("mydata.txt", usecols = (1,4,5), skiprows=4, delimiter="\t")
# this example loads data from the second, the fifth, and the sixth column and skips the header
# Load all columns be removing the usecols argument

Please find all options here: https://docs.scipy.org/doc/numpy-1.13.0/reference/generated/numpy.loadtxt.html

QtiPlot

tbf

Gnuplot

tbf