# Time: O(n)
# Space: O(1)
class Solution(object):
def pivotIndex(self, nums):
"""
:type nums: List[int]
:rtype: int
"""
total = sum(nums)
left_sum = 0
for i, num in enumerate(nums):
if left_sum == (total-left_sum-num):
return i
left_sum += num
return -1
table = pd.pivot_table(df, values='D', index=['A', 'B'],
... columns=['C'], aggfunc=np.sum, fill_value=0)
>>> table
C large small
A B
bar one 4 5
two 7 6
foo one 4 1
two 0 6