有一些通用的參數,比如
- axis=0為行?,1為列
- index=指定行,columns=指定列
- ascending=False倒序,True順序
找不到代碼時候試試會有驚喜
? | 行 | 列 | 通用 |
通過標簽選擇數據 |
df[[...]]
df.loc[' '] |
df[' '] | df.loc[indexList,columnList]? |
通過位置選擇數據 | df[num] | ? | df.iloc[indexList,columnList]? |
通過標簽/位置選擇數據 | ? | ? |
df.ix[indexList,columnList]
,如 df.ix[[1,2],['a',b']] |
隨機選擇數據 | ? | ? | samples = df.sample(n=num, random_state=time, axis=0行1列) |
條件選擇 | df = df.loc[:, df.loc['type'] == ...] | ? | ? |
? | ? | ? | ? |
刪除 | df.drop(index=['index']) | df.drop(columns=['column']) | ? |
? | ? | ? | ? |
追加/修改 |
df.loc[' '] = list
df = pd.concat([df1, df2], axis=0) |
df[' '] = list
df = pd.concat([df1, df2], axis=1) |
其他同理,用選擇數據的語句賦值 |
? | ? | ? | ? |
其他 | 多數解決方式——參數+axis=0 | 多數解決方式——參數+axis=1 | ? |
修改格式 | ? | ? | dataSet.astype('float') |
行列名 | df.index | df.columns | ? |
內容排序 | df.sort_values(' ',axis=0, ascending=False) | df.sort_values(' ',axis=1, ascending=False) | ?ascending=False倒序True順序 |
行列名排序 | sort_index(axis=0, ascending=False) | sort_index(axis=1, ascending=False) | ? |
更多文章、技術交流、商務合作、聯系博主
微信掃碼或搜索:z360901061

微信掃一掃加我為好友
QQ號聯系: 360901061
您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點擊下面給點支持吧,站長非常感激您!手機微信長按不能支付解決辦法:請將微信支付二維碼保存到相冊,切換到微信,然后點擊微信右上角掃一掃功能,選擇支付二維碼完成支付。
【本文對您有幫助就好】元
