Loading data files: Difference between revisions

From SweepMe! Wiki
Jump to navigation Jump to search
(Created page with "== 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...")
 
 
(15 intermediate revisions by the same user not shown)
Line 1: Line 1:
Last update with: Version 1.5.3.15
== Origin ==
== 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.
Just drag and drop the saved data files into Origin and select standard Ascii-import. Long name, unit are automatically filled with the two header lines. Make sure that the decimal separator is set to point in the options of Origin.


== Python ==
== Python ==


The data files can easily be loaded using the numpy package:
=== numpy ===
The data files can easily be loaded using the package [http://www.numpy.org/ numpy]:
 
{{syntaxhighlight|lang=python|code=
import numpy as np  # loading numpy package
 
data =  np.genfromtxt("mydata.txt", usecols = (0,2,3), skip_header = 3, 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.
 
{{syntaxhighlight|lang=python|code=
import numpy as np  # loading numpy package
 
data =  np.loadtxt("mydata.txt", usecols = (1,4,5), skiprows=3, 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
 
=== pandas ===
 
Another opportunity is to use the package [https://pandas.pydata.org/ pandas]:
{{syntaxhighlight|lang=python|code=
import pandas as pd
 
file = "Name of my data file.txt"
data = pd.read_csv('%s' % file, header=[0,1], delimiter='\t')
# the first two lines of the header are read
 
V = data[('SMU1 Voltage', 'V')].to_numpy()
I = data[('SMU2 Current', 'A')].to_numpy()
# Syntax: data[('<Module label> <space> <variable>', '<unit>')]
}}
 
Please find all options here:
https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.read_csv.html
 
== Matlab ==
tbd
 
== QtiPlot ==
tbd


numpy.genfromtxt
== Gnuplot ==
tbd

Latest revision as of 17:53, 1 January 2021

Last update with: Version 1.5.3.15

Origin

Just drag and drop the saved data files into Origin and select standard Ascii-import. Long name, unit are automatically filled with the two header lines. Make sure that the decimal separator is set to point in the options of Origin.

Python

numpy

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

import numpy as np  # loading numpy package

data =  np.genfromtxt("mydata.txt", usecols = (0,2,3), skip_header = 3, 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=3, 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

pandas

Another opportunity is to use the package pandas:

import pandas as pd

file = "Name of my data file.txt"
data = pd.read_csv('%s' % file, header=[0,1], delimiter='\t')
# the first two lines of the header are read

V = data[('SMU1 Voltage', 'V')].to_numpy()
I = data[('SMU2 Current', 'A')].to_numpy()
# Syntax: data[('<Module label> <space> <variable>', '<unit>')]

Please find all options here: https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.read_csv.html

Matlab

tbd

QtiPlot

tbd

Gnuplot

tbd