import pandas as pd
from pandas import Series
import numpy as np
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])
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)
# print(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()
print(sc2[0:10])
# ------------------------按值进行排序----------------------
sc3 = series_custom.sort_values()
print(sc3[0:10])
# ------------------------常用的数值计算---------------------------
np.add(series_custom, series_custom)
np.sin(series_custom)
np.max(series_custom)
# --------------------把大于50的值赋给series_greater_than_50----------------------
series_greater_than_50 = series_custom[series_custom > 50]
# --------------------把大于50且小于75的值赋给both_criteria----------------------
criteria_one = series_custom > 50
criteria_two = series_custom < 75
both_criteria = series_custom[criteria_one & criteria_two]
print(both_criteria)
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
Pandas.Series的某些特殊操作
©著作权归作者所有,转载或内容合作请联系作者
- 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
- 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
- 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
推荐阅读更多精彩内容
- 简介: 本文主要介绍DataFrame过滤数据的方法和原理。 过滤机制 可以按照下列方法,依据列的值过滤DataF...