zoukankan      html  css  js  c++  java
  • pandas学习之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)
  • 相关阅读:
    14.9 InnoDB Row Storage and Row Formats InnoDB 行存储和行格式:
    14.8.3 Identifying the File Format in Use 确认使用的文件格式;
    14.8.2 Verifying File Format Compatibility 校验文件格式兼容性:
    14.8.2 Verifying File Format Compatibility 校验文件格式兼容性:
    14.8.1 Enabling File Formats
    14.6.7?Limits on InnoDB Tables InnoDB 表的限制
    第2章 PCI总线的桥与配置 分类: 浅谈PCI 2013-07-22 16:27 281人阅读 评论(0) 收藏
    1.5 PCI-X总线简介 分类: 浅谈PCI 2013-07-22 16:27 290人阅读 评论(0) 收藏
    1.4 PCI总线的中断机制 分类: 浅谈PCI 2013-07-22 16:27 313人阅读 评论(0) 收藏
    1.3 PCI总线的存储器读写总线事务 分类: 浅谈PCI 2013-07-22 16:26 261人阅读 评论(0) 收藏
  • 原文地址:https://www.cnblogs.com/lifengwu/p/9816683.html
Copyright © 2011-2022 走看看