Added links

This commit is contained in:
David Beazley
2020-05-26 15:05:19 -05:00
parent d6680ea5b8
commit 48351b62ca
6 changed files with 28 additions and 26 deletions

View File

@@ -253,7 +253,7 @@ our goal.
Start this exercise by creating a new file called `fileparse.py`. This is where we will be doing our work.
### (a) Reading CSV Files
### Exercise 3.3: Reading CSV Files
To start, lets just focus on the problem of reading a CSV file into a
list of dictionaries. In the file `fileparse.py`, define a simple
@@ -300,7 +300,7 @@ Hint: `python3 -i fileparse.py`.
This is great except that you cant do any kind of useful calculation with the data because everything is represented as a string.
Well fix this shortly, but lets keep building on it.
### (b) Building a Column Selector
### Exercise 3.4: Building a Column Selector
In many cases, youre only interested in selected columns from a CSV file, not all of the data.
Modify the `parse_csv()` function so that it optionally allows user-specified columns to be picked out as follows:
@@ -318,7 +318,7 @@ Modify the `parse_csv()` function so that it optionally allows user-specified co
>>>
```
An example of a column selector was given in Section 2.5.
An example of a column selector was given in [Exercise 2.23](../02_Working_with_data/06_List_comprehension).
However, heres one way to do it:
```python
@@ -394,7 +394,7 @@ When you read a row of data from the file, the indices are used to filter it:
>>>
```
### (c) Performing Type Conversion
### Exercise 3.5: Performing Type Conversion
Modify the `parse_csv()` function so that it optionally allows type-conversions to be applied to the returned data.
For example:
@@ -410,7 +410,7 @@ For example:
>>>
```
You already explored this in Exercise 2.7. You'll need to insert the
You already explored this in [Exercise 2.24](../02_Working_with_data/07_Objects). You'll need to insert the
following fragment of code into your solution:
```python
@@ -420,7 +420,7 @@ if types:
...
```
### (d) Working with Headers
### Exercise 3.6: Working with Headers
Some CSV files dont include any header information.
For example, the file `prices.csv` looks like this:
@@ -448,7 +448,7 @@ line of data isnt interpreted as a header line. Also, youll need to
make sure you dont create dictionaries as there are no longer any
column names to use for keys.
### (e) Picking a different column delimitier
### Exercise 3.7: Picking a different column delimitier
Although CSV files are pretty common, its also possible that you could encounter a file that uses a different column separator such as a tab or space.
For example, the file `Data/portfolio.dat` looks like this:
@@ -486,6 +486,4 @@ You can use it to parse arbitrary CSV files, select out columns of
interest, perform type conversions, without having to worry too much
about the inner workings of files or the `csv` module.
Nice!
[Next](03_Error_checking)
[Contents](../Contents) \| [Previous (3.1 Scripting)](01_Script) \| [Next (3.3 Error Checking)](03_Error_checking)