|
| 1 | +import numpy as np |
| 2 | +import pandas as pd |
| 3 | +import matplotlib.pyplot as plt |
| 4 | +import cv2 |
| 5 | + |
| 6 | + |
| 7 | + |
| 8 | +""" |
| 9 | +1. A company needs to analyze the new covid stats for march 28th 2022. |
| 10 | +Download csv file os those stats and plot them on a bar graph |
| 11 | +""" |
| 12 | + |
| 13 | +def download_and_plot_data(): |
| 14 | + live_covid_data_url = "https://raw.githubusercontent.com/CSSEGISandData/COVID-19/master/csse_covid_19_data/csse_covid_19_time_series/time_series_covid19_confirmed_global.csv" |
| 15 | + df = pd.read_csv(live_covid_data_url) |
| 16 | + df.head() |
| 17 | + df.tail() |
| 18 | + df.dropna(inplace=True) |
| 19 | + df.drop(['Lat','Long'],axis=1,inplace=True) |
| 20 | + # plot data for only 27th march 2022 |
| 21 | + df_27th_march_2022 = df.loc[df['3/27/22']>0] |
| 22 | + # create a new df with only 'Country/Region' and '3/27/22' columns |
| 23 | + df_27th_march_2022 = df_27th_march_2022[['Country/Region','3/27/22']] |
| 24 | + # save to a csv file |
| 25 | + df_27th_march_2022.to_csv('27th_march_2022.csv') |
| 26 | + # plot data |
| 27 | + df_27th_march_2022.head() |
| 28 | + df_27th_march_2022.tail() |
| 29 | + df_27th_march_2022.plot(kind='bar', x=df_27th_march_2022['Country/Region'] , y=df_27th_march_2022['3/27/22']) |
| 30 | + plt.show() |
| 31 | + |
| 32 | + |
| 33 | +# download_and_plot_data() |
| 34 | + |
| 35 | +""" |
| 36 | +2. Those same stats, the company wants you to find the total average of new cases from each country. |
| 37 | +""" |
| 38 | + |
| 39 | +def total_average_of_new_cases_from_each_country(): |
| 40 | + df = pd.read_csv('27th_march_2022.csv') |
| 41 | + avg = df.groupby('Country/Region').sum().mean() |
| 42 | + avg.sort_values(ascending=False,inplace=True) |
| 43 | + avg.head() |
| 44 | + avg.tail() |
| 45 | + print(avg) |
| 46 | + |
| 47 | +def print_hello(): |
| 48 | + print('hello world') |
| 49 | + |
| 50 | +print_hello() |
| 51 | +""" |
| 52 | +3. create a video image with open-cv2 and draw "x" on the video image |
| 53 | +""" |
| 54 | + |
| 55 | +def create_and_draw_on_video_image(): |
| 56 | + cap = cv2.VideoCapture(0) |
| 57 | + while True: |
| 58 | + ret, frame = cap.read() |
| 59 | + # write "x" on the video image |
| 60 | + cv2.putText(frame, "X", (150,150), cv2.FONT_HERSHEY_COMPLEX, 1, (0,0,255), 2) |
| 61 | + cv2.imshow('frame',frame) |
| 62 | + if cv2.waitKey(1) & 0xFF == ord('q'): |
| 63 | + break |
| 64 | + cap.release() |
| 65 | + cv2.destroyAllWindows() |
| 66 | + |
| 67 | + |
| 68 | + |
| 69 | +def main(): |
| 70 | + # 1. |
| 71 | + #download_and_plot_data() |
| 72 | + |
| 73 | + # 2. |
| 74 | + #total_average_of_new_cases_from_each_country() |
| 75 | + |
| 76 | + # 3. |
| 77 | + create_and_draw_on_video_image() |
| 78 | + |
| 79 | +# run main program |
| 80 | +if __name__ == '__main__': |
| 81 | + main() |
0 commit comments