blogs
chronicles
dukeleto.factor
Math::GSL
dukeleto.pl
me
code
gitweb
math
pics
travel
writing
|
- Import Google Adsense Reports into Mathematica - Google adsense provides reports in "CSV" (aka Comma-Seperated Value) and it would
be nice to be able to plot and analyze this data in Mathematica. For some reason, Google's actual report format is broken. The file has a tab
character as a field delimiter, and sometimes uses two or three spaces instead of tab as well as inserting unprintable characters. I wrote
this simple perl script to take care of this mess:
#!/usr/bin/perl -w
# Cleans nonstandard characters that adsense puts in CSV files so
# that they can be imported to Excel, Mathematica, etc...
use strict;
while (<>){
# turn at least two spaces into a tab
$_ =~ s/\s{2,}/\t/g;
# delete anything funky that adsense puts in the csv file
$_ =~ s/[^A-Za-z0-9\s\t.%-]+//g;
print $_ ;
}
Then importng a standard file format into Mathematica is as simple as
alltime = Import["/home/user/adsense/alltime", "TSV"];
alltime // TableForm
This will save the file into a Mathematica matrix alltime, as well as printing it out in table form.
To download your reports from Google Adsense, first click on the "Advanced Reports" tab on the top left, and then
click on the CSV link on the top right-hand corner of the report. This should prompt you to save "report.csv".
|
|