Loading tabular data#
How to load data from a tsv file#
We can load a file containing tab seperated values with the load_tabular
app, providing it with the appropriate separator, sep="\t"
.
from cogent3 import get_app
load_tsv_app = get_app("load_tabular", sep="\t")
tsv_data = load_tsv_app("data/stats.tsv")
tsv_data
Locus | Region | Ratio |
---|---|---|
NP_003077 | Con | 2.5386 |
NP_004893 | Con | 121351.4264 |
NP_005079 | Con | 9516594.9789 |
NP_005500 | NonCon | 0.0000 |
NP_055852 | NonCon | 10933217.7090 |
5 rows x 3 columns
How to load data from a csv file#
We can load a file containing comma seperated values with the load_tabular
app, providing it with the seperator, sep=","
.
In the above example, data
is a cogent3.util.Table
object, if we write it to disk in csv format, we can re-use it for this example too.
Tip
If you are executing this code on your machine, replace path_to_csv_file
with the path containing your csv file!
from cogent3 import get_app
tsv_data.write(path_to_csv_file, sep=",")
load_csv_app = get_app("load_tabular", sep=",")
csv_data = load_csv_app(path_to_csv_file)
csv_data
Locus | Region | Ratio |
---|---|---|
NP_003077 | Con | 2.5386 |
NP_004893 | Con | 121351.4264 |
NP_005079 | Con | 9516594.9789 |
NP_005500 | NonCon | 0.0000 |
NP_055852 | NonCon | 10933217.7090 |
5 rows x 3 columns