Python-Pandas(5)核心数据结构Series详解

原创 2017年08月13日 09:55:18
#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 pd
fandango = 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 pandas
from pandas import Series

film_names = series_film.values
#print type(film_names)
#print film_names
rt_scores = series_rt.values
#print rt_scores
series_custom = Series(rt_scores , index=film_names)
series_custom[['Minions (2015)', 'Leviathan (2014)']]

这里写图片描述

# int index is also aviable
series_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_index
sorted_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 NumPy
import numpy as np
# Add each value with each other
print np.add(series_custom, series_custom)
# Apply sine function to each value
np.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 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

这里写图片描述

#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)

这里写图片描述

版权声明:本文为博主原创文章,未经博主允许不得转载。

python pandas dataframe 小结(包括集合set)

python pandas dataframe 小结(包括集合set)最近处理一些数据,发现很多坑,踩了之后又忘了又掉坑里,又去找度娘,太低效了。因此花时间总结一下,共勉!!1.df.shape ...

python 从fastq文件中挑选出序列长度在规定范围的序列

python 从fastq文件中挑选出序列长度在规定范围的序列 FASTQ文件长度过滤

[Python数据分析-01]Pandas数据结构之Series

# 导入pandas包import pandas as pd# Pandas主要有两个数据结构:Series和DataFrame,这里我们介绍Series的使用方法 # Series是一种类似一维数组...

Python数据分析入门(一)-Pandas数据结构(Series)

Series是一种类似于一维数组的对象,具有标签(或者说索引),下面将介绍Series对象的常用方法及操作 导包 import pandas as pd import numpy as np ...

pandas数据结构Series学习

pandas数据结构Series学习

pandas的数据结构-Series

要是用pandas,你首先得了解它的两个主要数据结构:Series和DataFrame,这里我将简单介绍一下Series Series,Python,pandas...

pandas数据结构之Series

Series 是一种类似于一维数组的对象,它由一组数据和一组与之相关的数据标签(lable)或者说索引(index)组成。 现在我们使用Series生成一个最简单的Series对象,因为没有给Seri...

Pandas 数据结构Series、DataFrame分析

用python进行数据分析时经常要用到pandas库,为了以后便于查询,我对pandas库的两个主要数据结构Series和DataFrame的创建和使用方法进行了简单总结。...

Pandas两种主要的数据结构--Series和DataFrame

(1)Series Series是一种类似与一维数组的对象,它由一组数据以及一组与之相关的数据便签(即索引)组成,仅由一组数据即可产生最简单的Series。 例如:a=Series([9,-3...

pandas&pandas学习教程&DataFrame与Series数据结构

安装: pandas的最小依赖项为: NumPy,python-dateutil,pytz 安装pandas前需先安装上述三个依赖项。 pandas官网文档强调,pandas项目名称中的字母应...
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:Python-Pandas(5)核心数据结构Series详解
举报原因:
原因补充:

(最多只允许输入30个字)