-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathlesson_3b.py
36 lines (25 loc) · 906 Bytes
/
lesson_3b.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
from sheetFeeder import dataSheet
import pandas as pd
import pandas_functions as pf
sheet_id = '19zHqOJt9XUGfrfzAXzOcr4uARgCGbyYiOtoaOCAMP7s'
sheet_range = 'Pandas!A:Z'
the_sheet = dataSheet(sheet_id, sheet_range)
# Put some sample data in the sheet
data1 = [['Col A', 'Col B', 'Col C', 'Col D'], [1.0, 2.0, 3.0, 4.0],
[5.0, 6.0, 7.0, 8.0], [0.0, 11.5, -5.0, 9.25]]
the_sheet.clear()
the_sheet.appendData(data1)
# 1. Get the data from the sheet (this is redundant, but just for demo purposes!)
ds = the_sheet.getData()
# 2. Convert to Pandas DataFrame
df = pf.datasheet_to_dataframe(sheet_id, sheet_range)
print(df)
print("")
# Add a column calculating the averages of each row
df['Average'] = df.mean(numeric_only=True, axis=1)
print(df)
# Convert back into array
data2 = pf.dataframe_to_datasheet(df)
# Post back to sheet, replacing data
the_sheet.clear()
the_sheet.appendData(data2)