np.random.randint产生一个范围内的数据

来源:互联网 发布:辉煌seo 编辑:程序博客网 时间:2024/06/05 04:50

在下面的例子中,生成一个15000到73001之间,398个数。

owners = np.random.randint(15000, high=73001, size=398, dtype='l')

owners

array([42103, 72637, 63969, 40944, 26670, 24258, 38820, 27586, 52873,       20782, 53881, 40945, 61277, 19927, 44753, 59667, 42084, 64075,       36582, 39701, 19795, 64105, 18650, 37933, 30183, 66188, 32658,       52519, 26128, 44239, 55123, 26857, 18727, 53778, 16010, 42865,       25540, 23386, 24829, 29189, 53164, 72063, 28464, 59719, 45994,       17814, 36364, 41259, 30545, 36911, 68944, 17390, 36238, 39773,       17564, 64535, 43698, 63488, 23852, 21125, 33372, 21763, 36120,       54465, 37676, 25754, 61541, 57381, 64805, 46451, 53774, 38532,       31168, 44824, 46971, 67859, 47634, 57427, 66953, 19883, 59683,       34818, 42250, 64617, 54011, 55430, 43742, 47846, 49169, 67707,       15045, 39765, 50945, 23538, 71719, 61586, 61281, 56529, 49445,       69569, 43499, 17633, 15656, 25661, 18409, 40159, 25266, 60750,       39353, 55570, 66595, 68170, 40308, 15258, 24682, 35704, 15114,       52568, 59614, 65410, 62478, 32799, 36997, 47010, 22972, 70562,       28103, 63454, 44195, 52151, 52672, 23072, 26441, 34478, 55645,       37660, 38394, 57295, 55813, 27231, 55928, 27301, 67442, 49701,       70725, 23418, 57035, 33764, 31175, 55120, 26982, 51042, 46761,       18817, 49793, 65919, 50693, 17462, 46269, 51433, 24581, 45738,       15490, 67025, 65204, 35138, 69851, 69132, 54670, 55704, 29516,       26953, 17038, 42550, 59265, 19704, 53378, 34827, 47133, 68627,       22124, 20781, 67779, 17324, 15767, 34063, 65303, 58138, 48376,       37182, 19211, 50989, 49537, 68980, 32257, 64461, 71363, 46413,       40555, 35674, 66210, 71830, 62106, 50791, 38536, 50914, 48890,       20149, 63123, 55634, 34501, 46371, 49068, 68121, 48660, 69471,       51651, 28405, 18207, 66205, 56502, 28032, 41633, 31603, 62342,       19413, 69828, 20711, 69544, 34945, 54364, 65768, 63329, 43294,       25346, 43060, 51615, 27704, 48242, 35854, 27038, 30928, 47375,       33062, 36940, 19560, 44416, 37439, 52915, 50323, 61674, 33836,       51395, 26023, 41235, 51881, 22187, 59448, 34274, 48283, 47418,       16350, 66872, 60095, 35102, 46022, 41665, 15495, 36893, 45113,       34224, 61046, 24948, 59441, 51938, 26837, 21309, 60503, 68609,       16350, 52426, 36915, 42289, 50751, 41655, 25902, 62246, 21053,       69483, 33216, 69627, 15814, 64995, 23250, 50910, 37151, 52963,       68605, 70467, 46144, 42668, 63119, 35862, 31177, 39687, 57647,       26434, 35016, 41379, 44149, 67155, 56986, 53297, 49113, 42056,       42973, 34040, 20280, 26672, 42047, 21494, 29004, 72861, 39527,       63388, 53164, 52939, 25621, 17020, 24555, 34274, 39627, 45648,       70088, 60387, 19512, 57538, 41370, 48846, 66575, 21420, 50841,       41724, 21911, 38594, 20735, 28268, 25636, 24169, 23825, 33514,       29950, 17332, 37885, 54033, 57133, 61772, 28121, 16447, 28308,       62309, 20239, 69569, 48242, 59504, 23110, 21450, 42215, 48606,       44779, 54454, 21808, 69698, 34811, 70036, 21226, 40798, 40777,       63527, 31439, 68564, 31262, 43662, 63787, 40530, 53060, 63478,       38400, 36328, 42975, 56931, 42978, 46891, 68741, 70611, 34683,       64549, 54989])


处理时间函数方法:

# print "January windspeeds:"

# creates a new column 'date' and gets the values from the index
data['date'] = data.index

# creates a column for each value from date
data['month'] = data['date'].apply(lambda date: date.month)
data['year'] = data['date'].apply(lambda date: date.year)
data['day'] = data['date'].apply(lambda date: date.day)

# gets all value from the month 1 and assign to janyary_winds
january_winds = data.query('month == 1')

# gets the mean from january_winds, using .loc to not print the mean of month, year and day
january_winds.loc[:,'RPT':"MAL"].mean()




原创粉丝点击