-
Notifications
You must be signed in to change notification settings - Fork 149
/
analyse_spreadsheet.py
52 lines (36 loc) · 1.37 KB
/
analyse_spreadsheet.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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import pandas as pd
def mean_temperature(data):
"""
Get the mean temperature
Args:
data (pandas.DataFrame): A pandas dataframe with air temperature measurements.
Returns:
The mean air temperature (float)
"""
temperatures = data['Air temperature (degC)']
return float(sum(temperatures) / len(temperatures))
def get_spreadsheet_columns(file_loc, print_columns=False):
"""Gets and prints the spreadsheet's header columns
Args:
file_loc (str): The file location of the spreadsheet
print_columns (bool, optional) : A flag used to print the columns to the console (default is False)
Returns:
a list of strings used that are the header columns
"""
file_data = pd.read_excel(file_loc)
column_headers = list(file_data.columns.values)
if print_columns:
print("\n".join(column_headers))
return column_headers
def main():
"""Analyse a spreadsheet file with temperatures.
Prompt the user for the file name, print the columns in the spreadsheet, and print the mean
temperature.
"""
file_loc = input('Provide the name of the excel file you want to analyse:')
get_spreadsheet_columns(file_loc, print_columns=True)
data = pd.read_excel(file_loc)
mean_temp = mean_temperature(data)
print(f'Mean temperature is: {mean_temp}')
if __name__ == '__main__':
main()