Write a Python solution for a Jupyter Notebook.
Task:
Fetch JSON from https://jsonplaceholder.typicode.com/users using requests.
Use an environment variable API_URL with a default fallback.
Set a timeout.
If the request fails, log a clear error and exit gracefully.
Define a dataclass or NamedTuple for one user row with:
id, name, email, city, company
Extract city from address and company name from company.
Handle missing nested fields safely.
Display the result as a formatted table using tabulate.
Use logging instead of print for success and error messages.
Write the same data to output/users.csv using csv and pathlib.Path.
Create the parent directory if needed.
Use type hints.
Do not use pandas.
I previously worked with [数据类型,例如 sales data / survey data / website logs / student records].
### 2. Challenges / data issues
-The data had [missing values / duplicated records / inconsistent formats / noisy text / outliers]. -Some fields were difficult to analyse because [原因].
### 3. How I handled the challenges
-I used [Excel / Python / Pandas / SQL / manual checking] to clean the data. -I removed or fixed [duplicates / missing values / formatting issues]. -I reorganised the dataset so it was easier to analyse.
### 4. What I learned
-I learned that data cleaning is essential before analysis. -I also learned that even simple data can become hard to use if the format is inconsistent. -This experience helped me understand the importance of structured and reproducible analysis.
| Column 1 | Column 2 | Column 3 | | -------- | -------- | -------- | | value 1 | value 2 | value 3 | | value 4 | value 5 | value 6 |
python
x = 2 y = 3 x + y
python
import matplotlib.pyplot as plt import numpy as np
x = np.linspace(0, 10, 100) y = np.sin(x)
plt.plot(x, y) plt.show()
python
fruits = ["apple", "banana", "cherry"]
for fruit in fruits: print(fruit)
python
word = "hello"
for char in word: print(char)
python
for i in range(5): print(i)
python
for i in range(1, 6): for j in range(1, 6): print(i * j, end="\t") print()
python
def greet(name): """ This function greets the person whose name is passed as an argument. """ print(f"Hello,{name}! Welcome to Python programming.")
python
greet("Alice") greet("James")
python
[ [1, 2, 3], [4, 5, 6], [7, 8, 9] ]
python
[ [1, 4, 7], [2, 5, 8], [3, 6, 9] ]
python
def transpose_matrix(matrix): """ This function takes a matrix (a list of lists) and returns its transpose. """ if not matrix or not matrix[0]: return []
rows = len(matrix) cols = len(matrix[0])
transpose = []
for col in range(cols): new_row = [] for row in range(rows): new_row.append(matrix[row][col]) transpose.append(new_row)
return transpose
matrix = [ [1, 2, 3], [4, 5, 6], [7, 8, 9] ]
transposed_matrix = transpose_matrix(matrix)
print("Original Matrix:") for row in matrix: print(row)
print("\nTransposed Matrix:") for row in transposed_matrix: print(row)