Skip to content

Commit cae284b

Browse files
filesystem graphic update reading chp
1 parent 32df820 commit cae284b

File tree

3 files changed

+14
-15
lines changed

3 files changed

+14
-15
lines changed

source/img/reading/filesystem.jpeg

-122 KB
Binary file not shown.

source/img/reading/filesystem.png

114 KB
Loading

source/reading.md

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -90,13 +90,12 @@ with respect to the computer's filesystem base (or *root*) folder, regardless of
9090

9191
Suppose our computer's filesystem looks like the picture in
9292
{numref}`Filesystem`. We are working in a
93-
file titled `worksheet_02.ipynb`, and our current working directory is `worksheet_02`;
93+
file titled `project3.ipynb`, and our current working directory is `project3`;
9494
typically, as is the case here, the working directory is the directory containing the file you are currently
9595
working on.
9696

97-
```{figure} img/reading/filesystem.jpeg
97+
```{figure} img/reading/filesystem.png
9898
---
99-
height: 500px
10099
name: Filesystem
101100
---
102101
Example file system
@@ -107,14 +106,14 @@ where the file is: using a relative path, or using an absolute path.
107106
The absolute path of the file always starts with a slash `/`—representing the root folder on the computer—and
108107
proceeds by listing out the sequence of folders you would have to enter to reach the file, each separated by another slash `/`.
109108
So in this case, `happiness_report.csv` would be reached by starting at the root, and entering the `home` folder,
110-
then the `dsci-100` folder, then the `worksheet_02` folder, and then finally the `data` folder. So its absolute
111-
path would be `/home/dsci-100/worksheet_02/data/happiness_report.csv`. We can load the file using its absolute path
109+
then the `dsci-100` folder, then the `project3` folder, and then finally the `data` folder. So its absolute
110+
path would be `/home/dsci-100/project3/data/happiness_report.csv`. We can load the file using its absolute path
112111
as a string passed to the `read_csv` function from `pandas`.
113112
```python
114-
happy_data = pd.read_csv("/home/dsci-100/worksheet_02/data/happiness_report.csv")
113+
happy_data = pd.read_csv("/home/dsci-100/project3/data/happiness_report.csv")
115114
```
116115
If we instead wanted to use a relative path, we would need to list out the sequence of steps needed to get from our current
117-
working directory to the file, with slashes `/` separating each step. Since we are currently in the `worksheet_02` folder,
116+
working directory to the file, with slashes `/` separating each step. Since we are currently in the `project3` folder,
118117
we just need to enter the `data` folder to reach our desired file. Hence the relative path is `data/happiness_report.csv`,
119118
and we can load the file using its relative path as a string passed to `read_csv`.
120119
```python
@@ -132,12 +131,12 @@ Python would look for a folder named `data` in the root folder of the computer&m
132131
```{index} see: .; path
133132
```
134133

135-
Aside from specifying places to go in a path using folder names (like `data` and `worksheet_02`), we can also specify two additional
134+
Aside from specifying places to go in a path using folder names (like `data` and `project3`), we can also specify two additional
136135
special places: the *current directory* and the *previous directory*. We indicate the current working directory with a single dot `.`, and
137-
the previous directory with two dots `..`. So for instance, if we wanted to reach the `bike_share.csv` file from the `worksheet_02` folder, we could
138-
use the relative path `../tutorial_01/bike_share.csv`. We can even combine these two; for example, we could reach the `bike_share.csv` file using
139-
the (very silly) path `../tutorial_01/../tutorial_01/./bike_share.csv` with quite a few redundant directions: it says to go back a folder, then open `tutorial_01`,
140-
then go back a folder again, then open `tutorial_01` again, then stay in the current directory, then finally get to `bike_share.csv`. Whew, what a long trip!
136+
the previous directory with two dots `..`. So for instance, if we wanted to reach the `bike_share.csv` file from the `project3` folder, we could
137+
use the relative path `../project2/bike_share.csv`. We can even combine these two; for example, we could reach the `bike_share.csv` file using
138+
the (very silly) path `../project2/../project2/./bike_share.csv` with quite a few redundant directions: it says to go back a folder, then open `project2`,
139+
then go back a folder again, then open `project2` again, then stay in the current directory, then finally get to `bike_share.csv`. Whew, what a long trip!
141140

142141
So which kind of path should you use: relative, or absolute? Generally speaking, you should use relative paths.
143142
Using a relative path helps ensure that your code can be run
@@ -149,20 +148,20 @@ across different computers. For example, suppose Fatima and Jayden are working o
149148
project together on the `happiness_report.csv` data. Fatima's file is stored at
150149

151150
```
152-
/home/Fatima/project/data/happiness_report.csv
151+
/home/Fatima/project3/data/happiness_report.csv
153152
```
154153

155154
while Jayden's is stored at
156155

157156
```
158-
/home/Jayden/project/data/happiness_report.csv
157+
/home/Jayden/project3/data/happiness_report.csv
159158
```
160159

161160
Even though Fatima and Jayden stored their files in the same place on their
162161
computers (in their home folders), the absolute paths are different due to
163162
their different usernames. If Jayden has code that loads the
164163
`happiness_report.csv` data using an absolute path, the code won't work on
165-
Fatima's computer. But the relative path from inside the `project` folder
164+
Fatima's computer. But the relative path from inside the `project3` folder
166165
(`data/happiness_report.csv`) is the same on both computers; any code that uses
167166
relative paths will work on both! In the additional resources section,
168167
we include a link to a short video on the

0 commit comments

Comments
 (0)