-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathread_data.py
29 lines (22 loc) · 946 Bytes
/
read_data.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
"""
Author: Amanjot Singh
Student number: 040956152
This class is responsible for reading and writing data to files.
"""
import pandas as pd
def import_data():
"""
This method uses the pandas library to read the file. read_csv accepts various arguments, first of which is file
name, then the index of columns to be imported and then the number of rows to be imported. The method uses error
handing to deal with missing files.
:return: returns the loaded data as a DataFrame object or error message if file not found
"""
try:
data = pd.read_csv("data/covid19.csv",
usecols=['pruid', 'prname', 'prnameFR', 'date',
'numconf', 'numprob', 'numdeaths',
'numtotal', 'numtoday', 'ratetotal'])
df = data.fillna(0)
return df
except FileNotFoundError:
print("File not found, try again")