mport pandas as pd import numpy as np fandango = pd.read_csv('fandango_score_comparison.csv') # -----------把FILM设置为index,drop=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)
pandas数据索引变换
最新推荐文章于 2024-04-22 20:29:04 发布