Import data from ftp file to mathematica

Viewed 50

I know this is probably very easy but I just can't figure it out. So I was trying this codes:

Import["ftp://aftp.cmdl.noaa.gov/products/trends/co2/co2_mm_mlo.txt"]

Or

data=Import["ftp://aftp.cmdl.noaa.gov/products/trends/co2/co2_mm_mlo.txt"]

Or

Import["ftp://aftp.cmdl.noaa.gov/products/trends/co2/co2_mm_mlo.txt", "Data"]

Or text or table instead of data and nothing is working, I just want to Import date from this file and show it in mathematica.... Someone know what I'm doing wrong? Thank you, Nina

1 Answers

The ftp is working. Maybe your firewall is blocking.

ftp = "ftp://aftp.cmdl.noaa.gov/products/trends/co2/co2_mm_mlo.txt";
data = Import[ftp, "Data"];
d2 = DeleteCases[data, _?(StringStartsQ[First[#], "#"] &)];
d3 = Catenate[StringSplit /@ d2];
d4 = ToExpression[d3[[All, {1, 2, 4}]]];
dates = {#1, #2} & @@@ d4;
avg = Last /@ d4;
DateListPlot[Transpose[{dates, avg}], PlotLabel -> "monthly average"]

enter image description here

Related