q28.py
· 460 B · Python
Eredeti
# Create a .csv file (with contents like age, weight and BMI). Read the content of the file and using Pandas and
# MatPlotLib, plot the graph.
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
data = pd.read_csv("data.csv")
bmi = []
for row in data.iterrows():
age, weight, height = row[1]
bmi.append(weight / (height / 100) ** 2)
data["BMI"] = bmi
figure, ax = plt.subplots()
ax.plot(data["age"], data["BMI"], "ro")
plt.show()
1 | # Create a .csv file (with contents like age, weight and BMI). Read the content of the file and using Pandas and |
2 | # MatPlotLib, plot the graph. |
3 | |
4 | import numpy as np |
5 | import pandas as pd |
6 | import matplotlib.pyplot as plt |
7 | |
8 | data = pd.read_csv("data.csv") |
9 | bmi = [] |
10 | for row in data.iterrows(): |
11 | age, weight, height = row[1] |
12 | bmi.append(weight / (height / 100) ** 2) |
13 | data["BMI"] = bmi |
14 | |
15 | figure, ax = plt.subplots() |
16 | ax.plot(data["age"], data["BMI"], "ro") |
17 | plt.show() |
18 |