[Python Cookbook] Pandas: Indexing of DataFrame
Posted Sherrrry
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了[Python Cookbook] Pandas: Indexing of DataFrame相关的知识,希望对你有一定的参考价值。
Selecting a Row
df.loc[index] # if index is a string, add ‘ ‘; if index is a number, no ‘ ‘
or
df.iloc[row_num]
Selecting a Column
df[‘col_name‘]
Or
df.col_name
Selecting an Element
df.loc[index, ‘col_name‘]
Selecting Multiple Discontinuous Rows
df.loc[[row_num1, row_num2, ...]] # can‘t use df.iloc here
Or
df.loc[bool_expr]
E.g.
nyc[nyc.cand_nm.isin(df11 p.cand nm)]
nyc[nyc.cand_nm.isnull()]
nyc[nyc.cand_nm.isnull()]
nyc[nyc.contb_receipt_amt >0]
以上是关于[Python Cookbook] Pandas: Indexing of DataFrame的主要内容,如果未能解决你的问题,请参考以下文章
[Python Cookbook] Pandas: 3 Ways to define a DataFrame
《Pandas CookBook》---- DataFrame基础操作