Seyfi
April 29, 2019, 11:51am
1
Hello I am new to Processing. I want to parse a csv file but it does not get it.
Can you help me please?
Thanks
My code is
Table table;
void setup() {
table = loadTable("C:/Users/Seyfi/Desktop/processing-3.5.3/mammals.csv", "header, csv");
println(table.getRowCount() + " total rows in table");
for (TableRow row : table.rows()) {
int id = row.getInt("id");
String species = row.getString("species");
String name = row.getString("name");
println(name + " (" + species + ") has an ID of " + id);
}
}
1 Like
kll
April 29, 2019, 12:17pm
3
the processing way is to make under the sketch dir
a subdir /data/ where you have files like
fonts
image
data
saved image/ pdf/ files( string / csv / json ) …
so please start with
String infile = "data/mammals.csv", outfile = "data/backup.csv";
table = loadTable(infile, "header, csv");
only this way you keep your data with the project and are mostly independent from OS the project is run from later.
also the install directory
processing-3.5.3
is a bad place for user data.
possibly you have a other problem,
where is your sketch directory?
/ File / Preferences /
Sketchbook location:
???
1 Like
Seyfi
April 29, 2019, 12:30pm
4
C:\Users\Seyfi\Desktop\processing-3.5.3\modes\java\application
This is where the sketch file is under. Is it fine?
kll
April 29, 2019, 12:45pm
5
no, i would call that a system directory
for the Processing 3.5.3
and also that that is under Desktop ( not totally bad, ) shows that you might not know how to handle disk and files under windows?
again, did you set that sketch path in the preferences?
Processing IDE / File / Preferences / Sketchbook location:
a windows way would be
C:\Users\Seyfi\Documents\projects\processing\
( make the dirs projects\processing\ first )
later when you use
Processing IDE / File / Sketchbook
that directory opens and show your sketches
my_sketch_1 ( click for open )
( contains: my_sketch_1/mysketch_1.pde )
1 Like
Seyfi
April 29, 2019, 12:54pm
6
kll:
IDE / File / Sketchbook
I dont know how to set sketch path, any reference can you recommend me?
I created a c:\Users\Seyfi\Documents\projects\processing\ folder\first , but dont know the rest .
Thanks
kll
April 29, 2019, 12:57pm
7
that is menu operation
[File]
…[Preferences]
1 Like
Seyfi
April 29, 2019, 2:01pm
8
Thank you so much for your help ad time
Seyfi
April 29, 2019, 2:08pm
9
Where should I put my csv file here?
Thanks
kll
April 29, 2019, 2:12pm
10
no, first save your code using
/ File / Save As /
so we can see that project in above directory
kll
April 29, 2019, 2:19pm
13
/TableS contains TableS.pde ?
down there you create /data/
/TableS/data/
and copy csv file into
/TableS/data/mammal.csv
and not forget to declare
String infile = "data/mammals.csv";
1 Like
Seyfi
April 29, 2019, 2:33pm
14
Thanks I really appreciate your help