pandas数据索引变换

mport pandas as pd
import numpy as np

fandango = pd.read_csv('fandango_score_comparison.csv')
# -----------FILM设置为indexdrop=False表示FILM的值依然保持,也就是多添加了一列FILM-------------------
fandango_films = fandango.set_index('FILM', drop=False)
print(fandango_films.index)

# ------------Avengers: Age of Ultron (2015)Hot Tub Time Machine 2 (2015)列两种方法----------------
print(fandango_films["Avengers: Age of Ultron (2015)":"Hot Tub Time Machine 2 (2015)"])
print(fandango_films.loc["Avengers: Age of Ultron (2015)":"Hot Tub Time Machine 2 (2015)"])

# --------------------打印Kumiko, The Treasure Hunter (2015)--------------------------
print(fandango_films.loc['Kumiko, The Treasure Hunter (2015)'])

# -------打印Kumiko, The Treasure Hunter (2015)', 'Do You Believe? (2015)', 'Ant-Man (2015)3---------
movies = ['Kumiko, The Treasure Hunter (2015)', 'Do You Believe? (2015)', 'Ant-Man (2015)']
print(fandango_films.loc[movies])

# ----------------------------------打印类型为float64的所有行--------------------------
types = fandango_films.dtypes
float_columns = types[types.values == 'float64'].index
float_df = fandango_films[float_columns]
print(float_df)

# --------------------------------对某一列求方差std----------------------------------
deviations = float_df.apply(lambda x: np.std(x))
print(deviations)

# --------------对行'RT_user_norm' 'Metacritic_user_nom'求方差----------------------
rt_mt_user = float_df[['RT_user_norm', 'Metacritic_user_nom']]
rt_mt_user.apply(lambda x: np.std(x), axis=1)
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值