| Map of China | View | Download | |
| List of links | View | Download | |
| List notebooks | View | Download | |
| Read a Microsoft Word file | View | Download |
create_spreadsheet(filename, strings).
As an example, calling
create_spreadsheet(
'cheese.xlsx',
['Cheddar', 'Wensleydale', 'Stilton']
)
cheese.xlsx
looking like this:
| A | B | |
|---|---|---|
| 1 | String | Length |
| 2 | Cheddar | 7 |
| 3 | Wensleydale | 11 |
| 4 | Stilton | 7 |
| 5 | Total | 25 |
filename will be a string ending with .xlsx and strings will be a list of strings.strings, consisting of the string itself and its length.B5 would be =SUM(B2:B4).
requirements.txt as explained
here, then you will already have this library installed.
On the university PCs you may need to install it as follows: at the top of the
VS Code window click on "Terminal" then "New Terminal" and type
pip install openpyxl.
import openpyxl
def create_spreadsheet(filename, strings):
wb = openpyxl.Workbook()
# ... etc ...
python_facing_right.jpg.
Display both images in your Jupyter notebook.
https://datasets-server.huggingface.co/rows?dataset=ceyda/smithsonian_butterflies&config=default&split=train&offset=0&length=5requests library to allow us to fetch data from the web.url be the URL as above, but with length=5 changed to length=100.dataset=requests.get(url).json() then data=dataset['rows'] to fetch the data.type(data) will tell you that data is a list. Entering
type(data[42]) will tell you that data[42] is a dict.
Entering data[42].keys() will tell you the keys of the dict.
The first key is row_idx, so you can enter data[42]['row_idx'],
but that just gives you the number 42 again, which is not useful; so you need
to try the other keys.
image_url, you can
display the image in your notebook by entering from PIL import Image
then img=Image.open(requests.get(image_url, stream=True).raw) then
img.
get_data() which returns data, and define a function
show_butterfly(data,k) which downloads and displays the image of
the butterfly in row k. Define another function
show_random_butterfly(data) that displays a randomly chosen butterfly.
taxonomy, which is a single
string containing words separated by commas. You can split the string at
the commas and then strip the spaces to get a list of words. The family
is the word in position 5 (counting from zero as usual). For example, the
very first butterfly in the dataset is in the family "Noctuidae".
Write a function family(data,k) which returns the family of the
butterfly in row k.