Untitled
In [1]:
import pandas as pd
import numpy as np
# def computeFile(fn):
# pa = pd.read_csv(fn)
# print(pa[‘price’])
In [2]:
computeFile(‘/Users/vagrant/tasks-2016/revenue/money-2016-02.csv’)
0 2500.0
1 2300.0
2 1700.0
3 1300.0
4 900.0
5 2200.0
6 1900.0
7 1200.0
8 4000.0
9 700.0
10 2500.0
11 1600.0
12 2700.0
13 0.0
14 700.0
15 1800.0
16 800.0
17 1800.0
18 1800.0
19 2000.0
20 4300.0
21 0.0
22 1400.0
23 3000.0
24 2000.0
25 5500.0
26 0.0
27 2800.0
28 2500.0
29 2560.0
…
158 6500.0
159 4800.0
160 1000.0
161 2300.0
162 1600.0
163 NaN
164 1800.0
165 0.0
166 1200.0
167 800.0
168 3000.0
169 1000.0
170 6800.0
171 800.0
172 2400.0
173 1000.0
174 500.0
175 1200.0
176 400.0
177 2500.0
178 200.0
179 700.0
180 400.0
181 600.0
182 1000.0
183 2300.0
184 NaN
185 NaN
186 NaN
187 NaN
Name: price, dtype: float64
In [3]:
upper = pd.read_csv(‘/Users/vagrant/tasks-2016/revenue/money-2016-02.csv’)
In [9]:
upper[upper[‘paykind’] == “taobao”][‘price’].sum()
Out[9]:
193748.0
In [10]:
upper[upper[‘paykind’] == “zhifubao”][‘price’].sum()
Out[10]:
59300.0
In [11]:
upper[upper[‘paykind’] == “paypal”][‘price’].sum()
Out[11]:
110460.0
In [13]:
upper[upper[‘paykind’] == “weixin”][‘price’].sum()
Out[13]:
18100.0
In [14]:
upper[‘price’].sum()
Out[14]:
385008.0
In [15]:
def computeAllKind(upper):
arr = [‘taobao’, ‘paypal’, ‘zhifubao’, ‘weixin’]
h = {}
for kind in arr:
h[kind] = upper[upper[‘paykind’] == kind][‘price’].sum()
return h
In [16]:
computeAllKind(upper)
Out[16]:
{‘paypal’: 110460.0,
‘taobao’: 193748.0,
‘weixin’: 18100.0,
‘zhifubao’: 59300.0}
In [17]:
lower = pd.read_csv(‘/Users/vagrant/tasks-2016/revenue/money-2016-07.csv’)
In [18]:
computeAllKind(lower)
Out[18]:
{‘paypal’: 212440.0,
‘taobao’: 193600.0,
‘weixin’: 44300.0,
‘zhifubao’: 64400.0}
In [19]:
lower[‘price’].sum()
Out[19]:
538920.0
In [ ]: