抵扣说明:
1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、C币套餐、付费专栏及课程。
Original: https://blog.csdn.net/keypig_zz/article/details/124536548
Author: 二向箔不会思考
Title: DRL基础(四)——编程:python与numpy基础
相关阅读
Title: DataFrame基本操作如何取列
import pandas as pd
import numpy as np
pd.options.display.max_columns = 40
#用列表选取多个列 dataframe[['列1','列2','列3','列4']]
movie = pd.read_csv('movie.csv')
movie_actor_director = movie[['Rank', 'Title', 'Genre', 'Director']]
movie_actor_director.head()
RankTitleGenreDirector01Guardians of the GalaxyAction,Adventure,Sci-FiJames Gunn12PrometheusAdventure,Mystery,Sci-FiRidley Scott23SplitHorror,ThrillerM. Night Shyamalan34SingAnimation,Comedy,FamilyChristophe Lourdelet45Suicide SquadAction,Adventure,FantasyDavid Ayer
选取单列 注意[[]]
# 选取单列 注意[[]] 返回的是DataFrame dataframe[]返回的是series
movie[['Director']].head()
Director0James Gunn1Ridley Scott2M. Night Shyamalan3Christophe Lourdelet4David Ayer
将列表分配给变量以便于进行多项选择
[En]
Assign a list to a variable to facilitate multiple selections
# 将列表赋值给一个变量,便于多选
cols=['Rank', 'Title', 'Genre', 'Director']
movie[cols]
RankTitleGenreDirector01Guardians of the GalaxyAction,Adventure,Sci-FiJames Gunn12PrometheusAdventure,Mystery,Sci-FiRidley Scott23SplitHorror,ThrillerM. Night Shyamalan……………997998Step Up 2: The StreetsDrama,Music,RomanceJon M. Chu998999Search PartyAdventure,ComedyScot Armstrong9991000Nine LivesComedy,Family,FantasyBarry Sonnenfeld
1000 rows × 4 columns
使用select_dtypes(),按类型选取列
# 使用select_dtypes(),选取浮点数列
movie.select_dtypes(include=['float']).head()
RatingRevenue (Millions)Metascore08.1333.1376.017.0126.4665.027.3138.1262.037.2270.3259.046.2325.0240.0
选取所有的数值列
# 选取所有的数值列
movie.select_dtypes(include=['number']).head()
RankYearRuntime (Minutes)RatingVotesRevenue (Millions)Metascore0120141218.1757074333.1376.01220121247.0485820126.4665.02320161177.3157606138.1262.03420161087.260545270.3259.04520161236.2393727325.0240.0
通过filter()函数过滤选取多列
# 通过filter()函数过滤选取多列
movie.filter(like='Year').head()
Year0201412012220163201642016
通过正则表达式选取多列 regex(Regular Expression)
# 通过正则表达式选取多列 regex(Regular Expression)
movie.filter(regex='\s').head()
Runtime (Minutes)Revenue (Millions)0121333.131124126.462117138.123108270.324123325.02
filter()函数,传递列表到参数items,选取多列
# filter()函数,传递列表到参数items,选取多列
movie.filter(items=['Year', 'Title']).head()
YearTitle02014Guardians of the Galaxy12012Prometheus22016Split32016Sing42016Suicide Squad
Original: https://blog.csdn.net/weixin_48135624/article/details/113824385
Author: 缘 源 园
Title: DataFrame基本操作如何取列
原创文章受到原创版权保护。转载请注明出处:https://www.johngo689.com/320400/
转载文章受原作者版权保护。转载请注明原作者出处!