1.销售趋势
2.买车的热门城市
3.车主偏爱的颜色
4.以北京为例,采购多来自经销商
怎么判断是经销商呢?上面的886买的车其实是由下面的人贡献的
5.卖的最好的车
6.真实的买家,很喜欢用手机号做用户名呀,如果我是卖保险的,那机会来了
7.大家偏爱的购买时间




>>> np.argsort(x) array([1, 2, 0]) 返回排序数据下表
Python中的sorted函数以及operator.itemgetter函数
operator.itemgetter函数
operator模块提供的itemgetter函数用于获取对象的哪些维的数据,参数为一些序号(即需要获取的数据在对象中的序号),下面看例子。
a = [1,2,3]
>>> b=operator.itemgetter(1) //定义函数b,获取对象的第1个域的值
>>> b(a)
2
>>> b=operator.itemgetter(1,0) //定义函数b,获取对象的第1个域和第0个的值
>>> b(a)
(2, 1)
要注意,operator.itemgetter函数获取的不是值,而是定义了一个函数,通过该函数作用到对象上才能获取值。
sorted函数
Python内置的排序函数sorted可以对list或者iterator进行排序,官网文档见:http://docs.python.org/2/library/functions.html?highlight=sorted#sorted,该函数原型为:
sorted(iterable[, cmp[, key[, reverse]]])
参数解释:
(1)iterable指定要排序的list或者iterable,不用多说;
(2)cmp为函数,指定排序时进行比较的函数,可以指定一个函数或者lambda函数,如:
students为类对象的list,没个成员有三个域,用sorted进行比较时可以自己定cmp函数,例如这里要通过比较第三个数据成员来排序,代码可以这样写:
students = [('john', 'A', 15), ('jane', 'B', 12), ('dave', 'B', 10)]
sorted(students, key=lambda student : student[2])
(3)key为函数,指定取待排序元素的哪一项进行排序,函数用上面的例子来说明,代码如下:
sorted(students, key=lambda student : student[2])
python字典 get()方法; 返回一个给定的key对应的值。如果key是没有用的,然后返回默认值None返回。
语法:
dict.get(key, default=None)
参数:
下面是详细参数:
- key:key在字典中查找。
- default:在key不存在的情况下返回值None。
1,广播:对 形状不同 的数组的运算采取的操作。但是这个输入的数组中必须有一个 某轴长度为1,或者缺 少了一个维度(这个时候会自动的在shape属性前面补上1)。例如:
>>> import numpy as np
>>> a=np.arange(10,50,10).reshape(-1,1)
>>> a.shape
(4, 1)
>>> b=np.arange(0,4)
>>> b
array([0, 1, 2, 3])
>>> b.shape
(4,)
>>> a+b
array([[10, 11, 12, 13],
[20, 21, 22, 23],
[30, 31, 32, 33],
[40, 41, 42, 43]])
numpy.sum
- numpy.sum(a, axis=None, dtype=None, out=None, keepdims=False)[source]
-
Sum of array elements over a given axis.
Parameters:
a : array_like
Elements to sum.
axis : None or int or tuple of ints, optional
Axis or axes along which a sum is performed. The default (axis = None) is perform a sum over all the dimensions of the input array. axis may be negative, in which case it counts from the last to the first axis.
New in version 1.7.0.
If this is a tuple of ints, a sum is performed on multiple axes, instead of a single axis or all the axes as before.
dtype : dtype, optional
The type of the returned array and of the accumulator in which the elements are summed. By default, the dtype of a is used. An exception is when a has an integer type with less precision than the default platform integer. In that case, the default platform integer is used instead.
out : ndarray, optional
Array into which the output is placed. By default, a new array is created. If out is given, it must be of the appropriate shape (the shape of a with axis removed, i.e., numpy.delete(a.shape, axis)). Its type is preserved. See doc.ufuncs (Section “Output arguments”) for more details.
keepdims : bool, optional
If this is set to True, the axes which are reduced are left in the result as dimensions with size one. With this option, the result will broadcast correctly against the original arr.
Returns:
sum_along_axis : ndarray
An array with the same shape as a, with the specified axis removed. If a is a 0-d array, or if axis is None, a scalar is returned. If an output array is specified, a reference to out is returned.
See also
- ndarray.sum
- Equivalent method.
- cumsum
- Cumulative sum of array elements.
- trapz
- Integration of array values using the composite trapezoidal rule.
Notes
Arithmetic is modular when using integer types, and no error is raised on overflow.
The sum of an empty array is the neutral element 0:
>>>>>> np.sum([])
0.0
Examples
>>>>>> np.sum([0.5, 1.5])
2.0
>>> np.sum([0.5, 0.7, 0.2, 1.5], dtype=np.int32)
1
>>> np.sum([[0, 1], [0, 5]])
6
>>> np.sum([[0, 1], [0, 5]], axis=0)
array([0, 6])
>>> np.sum([[0, 1], [0, 5]], axis=1)
array([1, 5])
If the accumulator is too small, overflow occurs:
>>>>>> np.ones(128, dtype=np.int8).sum(dtype=np.int8)
-128