Python-Pandas(5)核心数据结构Series详解
来源:互联网 发布:dva矩阵 编辑:程序博客网 时间:2024/05/22 14:39
#Series (collection of values)#DataFrame (collection of Series objects)#Panel (collection of DataFrame objects)
#A Series object can hold many data types, including#float - for representing float values#int - for representing integer values#bool - for representing Boolean values#datetime64[ns] - for representing date & time, without time-zone#datetime64[ns, tz] - for representing date & time, with time-zone#timedelta[ns] - for representing differences in dates & times (seconds, minutes, etc.)#category - for representing categorical values#object - for representing String values#FILM - film name#RottenTomatoes - Rotten Tomatoes critics average score#RottenTomatoes_User - Rotten Tomatoes user average score#RT_norm - Rotten Tomatoes critics average score (normalized to a 0 to 5 point system)#RT_user_norm - Rotten Tomatoes user average score (normalized to a 0 to 5 point system)#Metacritic - Metacritic critics average score#Metacritic_User - Metacritic user average score
import pandas as pdfandango = pd.read_csv('fandango_score_comparison.csv')series_film = fandango['FILM']print(series_film[0:5])series_rt = fandango['RottenTomatoes']print (series_rt[0:5])
# Import the Series object from pandasfrom pandas import Seriesfilm_names = series_film.values#print type(film_names)#print film_namesrt_scores = series_rt.values#print rt_scoresseries_custom = Series(rt_scores , index=film_names)series_custom[['Minions (2015)', 'Leviathan (2014)']]
# int index is also aviableseries_custom = Series(rt_scores , index=film_names)series_custom[['Minions (2015)', 'Leviathan (2014)']]fiveten = series_custom[5:10]print(fiveten)
original_index = series_custom.index.tolist()#print original_indexsorted_index = sorted(original_index)sorted_by_index = series_custom.reindex(sorted_index)#print sorted_by_index
sc2 = series_custom.sort_index()sc3 = series_custom.sort_values()#print(sc2[0:10])print(sc3[0:10])
#The values in a Series object are treated as an ndarray, the core data type in NumPyimport numpy as np# Add each value with each otherprint np.add(series_custom, series_custom)# Apply sine function to each valuenp.sin(series_custom)# Return the highest value (will return a single value not a Series)np.max(series_custom)
#will actually return a Series object with a boolean value for each filmseries_custom > 50series_greater_than_50 = series_custom[series_custom > 50]criteria_one = series_custom > 50criteria_two = series_custom < 75both_criteria = series_custom[criteria_one & criteria_two]print both_criteria
#data alignment same indexrt_critics = Series(fandango['RottenTomatoes'].values, index=fandango['FILM'])rt_users = Series(fandango['RottenTomatoes_User'].values, index=fandango['FILM'])rt_mean = (rt_critics + rt_users)/2print(rt_mean)
阅读全文
0 0
- Python-Pandas(5)核心数据结构Series详解
- pandas核心数据结构series详解
- python-pandas-Series和DataFrame数据结构构建
- pandas数据结构Series学习
- Pandas数据结构之:Series
- Pandas数据结构-Series
- pandas数据结构之Series
- python pandas series
- python-pandas-series
- Python Pandas常用数据结构Series和DataFrame的相关操作
- Python数据分析入门(一)-Pandas数据结构(Series)
- [Python数据分析-01]Pandas数据结构之Series
- Pandas 数据结构(Series,DataFrame)
- pandas的数据结构-Series
- Pandas 数据结构Series、DataFrame分析
- 第5章-1 Pandas的数据结构介绍Series
- Pandas核心数据结构
- 数据结构之--series,DataFrame.use python and pandas for data mining
- 求割点(邻接表无向图)C~
- 北京武汉企业商会同仁参观考察亨瑞集团北京总部
- vector
- 看懂UML类图和时序图
- 马来西亚交通部长来访汪国新北京诗书画院
- Python-Pandas(5)核心数据结构Series详解
- 笔试题 5
- Hexo + Github Pages搭建个人独立博客
- 中国航油前总裁参观汪国新北京诗书画院
- 二分查找的三种方式
- AIX基本操作命令
- 最近比较火的10篇大数据文章,看看你错过了哪篇?
- [Leetcode] 354. Russian Doll Envelopes 解题报告
- (转)三年后,我手里的比特币值多少钱