Pandas_Numpy_cheatsheet

Pandas Cheatsheet

First refers to pandas DataFrame cheatsheet.pdf

Series

DataFrame

Initialization

Load and write data from other sources

  • csv
  • MySQL
  • Hadoop (impyla(as_pandas), happybase)

Woring with row and column index

df.index
df.columns

Work with columns of data (axis=1)

Work with rows of data (axis=0)

Work with cells

  • do a comprehensive summary of pandas indexing !!!

Join/combine DataFrame

Split DataFrame

  • use list comprehension

target = [x[11] for x in dataset]
train = [x[0:11] for x in dataset]

Work with whole DataFrame

Work with dates, times and their indexes

Work with strings

Work with missing and non-finite value

Basic Statistics

Work with Categorical data

Annoying Part:

Copy vs View

use of direct index will return a new copy of data, therefore is not recommended for modify things
http://stackoverflow.com/questions/20625582/how-to-deal-with-this-pandas-warning
From what I gather, SettingWithCopyWarning was created to flag potentially confusing "chained" assignments, such as the following, which don't always work as expected, particularly when the first selection returns a copy. [see GH5390 and GH5597 for background discussion.]

df[df['A'] > 2]['B'] = new_val # new_val not set in df
The warning offers a suggestion to rewrite as follows:

df.loc[df['A'] > 2, 'B'] = new_val
However, this doesn't fit your usage, which is equivalent to:

df = df[df['A'] > 2]
df['B'] = new_val

modify in place vs return a new value

index of row and column

select index from row or column by direct index is extremely similar with subtle difference:

change column name

change of column order

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

  • 最近在寫個性化推薦的論文,經(jīng)常用到Python來處理數(shù)據(jù),被pandas和numpy中的數(shù)據(jù)選取和索引問題繞的比較...
    shuhanrainbow閱讀 4,700評論 6 19
  • 努力 2013/09/09 看了那些個案例,他們真的很拼命,想盡法子功成名就。我呢,就像個百無聊賴的老頭,慢悠悠地...
    nutpoem閱讀 456評論 0 0
  • 投資就是現(xiàn)在投入一筆錢,獲得未來的現(xiàn)金流。 嗯,說完了。 下面是各種可能的狀況: A:如果“未來現(xiàn)金流”是零,這叫...
    郁金香札記閱讀 758評論 0 0

友情鏈接更多精彩內(nèi)容