numpy学习之Series结构

Posted lifengwu

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了numpy学习之Series结构相关的知识,希望对你有一定的参考价值。

#!/usr/bin/env python
# -*- coding:utf-8 -*-
"""
系列(值的集合)
DataFrame数据包(系列对象的集合)
panel(数据文件对象的集合)
一个系列对象可以保存许多数据类型,包括
浮点数表示浮点数
表示整数值的
布尔布尔值表示布尔值
表示日期和时间,没有时区的
用日期时区表示日期和时间
表示时间和时间(秒,分钟等)的差异的时间δ[NS]
表示类别值的类别
表示字符串值的对象
电影胶片名
# rottentomatoes -烂番茄影评平均得分
# rottentomatoes_user烂番茄用户平均得分
# rt_norm -烂番茄影评平均得分(归一化到0到5点的系统)
# rt_user_norm烂西红柿用户平均得分(归一化到0-5点系统)
亚元主义-元主义批评家平均分
亚元用户-元用户平均得分
"""
#series结构 学习
import pandas as pd
import numpy as np
fandango = pd.read_csv(fandango_score_comparison.csv)
series_film = fandango[FILM]
print(type(series_film))
print(series_film[0:5])  #FILM这一列前0-5个
series_rt = fandango[RottenTomatoes]   #RottenTomatoes前0-5个
print(series_rt[0:5])

from pandas import Series

film_names = series_film.values
print(type(film_names))
#print(film_names)
rt_scores = series_rt.values  #得分值来自:RottenTomatoes
#print(rt_scores)
series_custom = Series(rt_scores,index=film_names) #以电影名字为索引
print(series_custom[[Minions (2015),Leviathan (2014)]]) #输出这两部电影的评分
fiveten = series_custom[5:10]  #以电影名字为索引,打印前5-10部电影和评分
print(fiveten)

sc2 = series_custom.sort_index()
sc3 = series_custom.sort_values()  #以这两种都可以进行排序 sc2[2:10}
print(np.add(series_custom,series_custom)) #相加操作

#will actually return a Series object with a boolean value for each film
series_custom > 50
series_greater_than_50 = series_custom[series_custom > 50]

criteria_one = series_custom > 50
criteria_two = series_custom < 75   #评分在这一段的电影和分数
both_criteria = series_custom[criteria_one & criteria_two]
print(both_criteria)
print(--------)
#data alignment same index
rt_critics = Series(fandango[RottenTomatoes].values, index=fandango[FILM])
rt_users = Series(fandango[RottenTomatoes_User].values, index=fandango[FILM])
rt_mean = (rt_critics + rt_users)/2   #两个媒体评分的平均值
print(rt_mean)
print(分割线——————)
print(type(fandango))
fandango_films = fandango.set_index("FILM",drop=False)
print(fandango_films.index)  #打印出索引值 列名
#在选择多行时,返回数据文件,但是选择一个单独的行时,将返回一个系列对象。
fandango_films["Avengers: Age of Ultron (2015)":"Hot Tub Time Machine 2 (2015)"]
fandango_films.loc["Avengers: Age of Ultron (2015)":"Hot Tub Time Machine 2 (2015)"]
# Specific movie
fandango_films.loc[Kumiko, The Treasure Hunter (2015)]
# Selecting list of movies
movies = [Kumiko, The Treasure Hunter (2015), Do You Believe? (2015), Ant-Man (2015)]
print(fandango_films.loc[movies])

print(继续分割——————)
types = fandango_films.dtypes
float_columns = types[types.values == float64].index  #类型转换
float_df = fandango_films[float_columns]
deviations = float_df.apply(lambda x: np.std(x))
rt_mt_user = float_df[[RT_user_norm,Metacritic_user_nom]]
rt_mt_user.apply(lambda x: np.std(x), axis=1) # 对以上两个列做了变换
print(rt_mt_user)

 

以上是关于numpy学习之Series结构的主要内容,如果未能解决你的问题,请参考以下文章

4_InfluxDB学习之InfluxDB的基本概念InfluxDB中独有的概念(Point,series),InfluxDB学习之InfluxDB的基本操作,InfluxDB操作方式,crud(代码

深度学习之手撕神经网络代码(基于numpy)

深度学习之手撕深度神经网络DNN代码(基于numpy)

python运算学习之Numpy ------ 数组的切片索引与循环遍历条件和布尔数组

python模块学习之numpy

python学习之numpy