15.08.2015 Views

Introduction to the Modeling and Analysis of Complex Systems

introduction-to-the-modeling-and-analysis-of-complex-systems-sayama-pdf

introduction-to-the-modeling-and-analysis-of-complex-systems-sayama-pdf

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

15.5. IMPORTING/EXPORTING NETWORK DATA 317values) file. Place this Python code in <strong>the</strong> same folder where <strong>the</strong> data file is located, runit, <strong>and</strong> you will get a result like Fig. 15.7 3 .JackJillJeffJaneJohnJessJoshFigure 15.7: Visual output <strong>of</strong> Code 15.14.Looks good. No—wait—<strong>the</strong>re is a problem here. For some reason, <strong>the</strong>re is an extranode without a name (at <strong>the</strong> <strong>to</strong>p <strong>of</strong> <strong>the</strong> network in Fig. 15.7)! What happened? The reasonbecomes clear if you open <strong>the</strong> CSV file in a text edi<strong>to</strong>r, which reveals that <strong>the</strong> file actuallylooks like this:Code 15.15:John,Jane,JackJess,Josh,JillJack,Jane,Jill,Jeff,Jeff,Jane,Note <strong>the</strong> commas at <strong>the</strong> end <strong>of</strong> <strong>the</strong> third, fourth, <strong>and</strong> fifth lines. Many spreadsheet applicationstend <strong>to</strong> insert <strong>the</strong>se extra commas in order <strong>to</strong> make <strong>the</strong> number <strong>of</strong> columns equalfor all rows. This is why NetworkX thought <strong>the</strong>re would be ano<strong>the</strong>r node whose name was“” (blank). You can delete those unnecessary commas in <strong>the</strong> text edi<strong>to</strong>r <strong>and</strong> save <strong>the</strong> file.Or you could modify <strong>the</strong> visualization code <strong>to</strong> remove <strong>the</strong> nameless node before drawing<strong>the</strong> network. Ei<strong>the</strong>r way, <strong>the</strong> updated result is shown in Fig. 15.8.3 If you can’t read <strong>the</strong> data file or get <strong>the</strong> correct result, it may be because your NetworkX did not recognizeoperating system-specific newline characters in <strong>the</strong> file (this may occur particularly for Mac users). You canavoid this issue by saving <strong>the</strong> CSV file in a different mode (e.g., “MS-DOS” mode in Micros<strong>of</strong>t Excel).

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!