-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathA_align_dataframe_inputs.py
More file actions
145 lines (91 loc) · 5.25 KB
/
A_align_dataframe_inputs.py
File metadata and controls
145 lines (91 loc) · 5.25 KB
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
'''
Created on May 2, 2022
@author: Jim Lakis
'''
import pandas as pd
import timeit
def main():
# Single quotes, single statement with the string literal assigned to a variable
# Format notes:
# Every line ends with a forward slash and the entire string is enclosed in single quotes
# Alignment within the assignment statement is irrelevant depicted by columns "Region" and "Team"
s_ment ='df1 = pd.DataFrame({\
"Region":["North","West","East","South","North","West","East","South"],\
"Team":["One","One","One","One","Two","Two","Two","Two"],\
"Squad":["A","B","C","D","E","F","G","H"],\
"Revenue":[7500,5500,2750,6400,2300,3750,1900,575],\
"Cost":[5200,5100,4400,5300,1250,1300,2100,50]\
})'
my_setup = 'from __main__ import pd'
print(timeit.timeit(setup = my_setup, stmt = s_ment, number = 100))
# ---
# Single quotes, single statement with the string literal defined directly within the timeit() function
# Format notes:
# Every line ends with a forward slash
# Alignment within the function is irrelevant depicted by columns "Region" and "Team"
my_setup = 'from __main__ import pd'
print(timeit.timeit(setup = my_setup, stmt = 'df1 = pd.DataFrame({\
"Region":["North","West","East","South","North","West","East","South"],\
"Team":["One","One","One","One","Two","Two","Two","Two"],\
"Squad":["A","B","C","D","E","F","G","H"],\
"Revenue":[7500,5500,2750,6400,2300,3750,1900,575],\
"Cost":[5200,5100,4400,5300,1250,1300,2100,50]\
})', number = 100))
# ---
# Single quotes, MULTIPLE statements with the string literal assigned to a variable
# Format notes:
# Every line statement ends with a semicolon and every line ends with a forward slash
# Alignment within the function and other statements is irrelevant
s_ment ='df1 = pd.DataFrame({\
"Region":["North","West","East","South","North","West","East","South"],\
"Team":["One","One","One","One","Two","Two","Two","Two"],\
"Squad":["A","B","C","D","E","F","G","H"],\
"Revenue":[7500,5500,2750,6400,2300,3750,1900,575],\
"Cost":[5200,5100,4400,5300,1250,1300,2100,50]\
}); ### <-- statement concludes with a semicolon, the lines ends with a forward slash --> \
x = 2'
my_setup = 'from __main__ import pd'
print(timeit.timeit(setup = my_setup, stmt = s_ment, number = 100))
# -------------------------------------------------------------------
# Triple quotes, single statement with the string literal assigned to a variable
# Format notes:
# No additional formatting; ie forward slashes
# Alignment within the assignment statement is irrelevant depicted by columns "Region" and "Team"
s_ment ='''df1 = pd.DataFrame({
"Region":["North","West","East","South","North","West","East","South"],
"Team":["One","One","One","One","Two","Two","Two","Two"],
"Squad":["A","B","C","D","E","F","G","H"],
"Revenue":[7500,5500,2750,6400,2300,3750,1900,575],
"Cost":[5200,5100,4400,5300,1250,1300,2100,50]
})'''
my_setup = 'from __main__ import pd'
print(timeit.timeit(setup = my_setup, stmt = s_ment, number = 100))
# ---
# Triple quotes, single statement with the string literal defined directly within the timeit() function
# Format notes:
# No additional formatting; ie forward slashes
# Alignment within the assignment statement is irrelevant depicted by columns "Region" and "Team"
my_setup = 'from __main__ import pd'
print(timeit.timeit(setup = my_setup, stmt = '''df1 = pd.DataFrame({
"Region":["North","West","East","South","North","West","East","South"],
"Team":["One","One","One","One","Two","Two","Two","Two"],
"Squad":["A","B","C","D","E","F","G","H"],
"Revenue":[7500,5500,2750,6400,2300,3750,1900,575],
"Cost":[5200,5100,4400,5300,1250,1300,2100,50]
})''', number = 100))
# ---
# Triple quotes, MULTIPLE statements with the string literal assigned to a variable
# Format notes:
# Only the conclusion of a statement ends with a semicolon and a forward slash
# Alignment within the function and other statements is irrelevant
my_setup = 'from __main__ import pd'
print(timeit.timeit(setup = my_setup, stmt = '''df1 = pd.DataFrame({
"Region":["North","West","East","South","North","West","East","South"],
"Team":["One","One","One","One","Two","Two","Two","Two"],
"Squad":["A","B","C","D","E","F","G","H"],
"Revenue":[7500,5500,2750,6400,2300,3750,1900,575],
"Cost":[5200,5100,4400,5300,1250,1300,2100,50]
}); ### <-- statement concludes with a semicolon, the lines ends with a forward slash --> \
x = 2''', number = 100))
if __name__ == '__main__':
main()