python數據分析包|Pandas&NumPy小抄(Cheat_Sheet)

2021-01-18 pythonic生物人
1、NumPy速查手冊一2、NumPy速查手冊二3、NumPy速查手冊二文本格式
#Importing/exporting#numpy讀入及保存內容
np.loadtxt('file.txt') | From a text file
np.genfromtxt('file.csv',delimiter=',') | From a CSV file
np.savetxt('file.txt',arr,delimiter=' ') | Writes to a text file
np.savetxt('file.csv',arr,delimiter=',') | Writes to a CSV file

#Creating Arrays#numpy創建數組
np.array([1,2,3]) | One dimensional array
np.array([(1,2,3),(4,5,6)]) | Two dimensional array
np.zeros(3) | 1D array of length 3 all values 0
np.ones((3,4)) | 3x4 array with all values 1
np.eye(5) | 5x5 array of 0 with 1 on diagonal (Identity matrix)
np.linspace(0,100,6) | Array of 6 evenly divided values from 0 to 100
np.arange(0,10,3) | Array of values from 0 to less than 10 with step 3 (eg [0,3,6,9])
np.full((2,3),8) | 2x3 array with all values 8
np.random.rand(4,5) | 4x5 array of random floats between 0–1
np.random.rand(6,7)*100 | 6x7 array of random floats between 0–100
np.random.randint(5,size=(2,3)) | 2x3 array with random ints between 0–4

#Inspecting Properties#numpy屬性
arr.size | Returns number of elements in arr
arr.shape | Returns dimensions of arr (rows,columns)
arr.dtype | Returns type of elements in arr
arr.astype(dtype) | Convert arr elements to type dtype
arr.tolist() | Convert arr to a Python list
np.info(np.eye) | View documentation for np.eye

#Copying/sorting/reshaping#numpy數組複製、排序、變形
np.copy(arr) | Copies arr to new memory
arr.view(dtype) | Creates view of arr elements with type dtype
arr.sort() | Sorts arr
arr.sort(axis=0) | Sorts specific axis of arr
two_d_arr.flatten() | Flattens 2D array two_d_arr to 1D
arr.T | Transposes arr (rows become columns and vice versa)
arr.reshape(3,4) | Reshapes arr to 3 rows, 4 columns without changing data
arr.resize((5,6)) | Changes arr shape to 5x6 and fills new values with 0

#Adding/removing Elements#nump添加和刪除元素
np.append(arr,values) | Appends values to end of arr
np.insert(arr,2,values) | Inserts values into arr before index 2
np.delete(arr,3,axis=0) | Deletes row on index 3 of arr
np.delete(arr,4,axis=1) | Deletes column on index 4 of arr

#Combining/splitting#numpy數組合併和拆分
np.concatenate((arr1,arr2),axis=0) | Adds arr2 as rows to the end of arr1
np.concatenate((arr1,arr2),axis=1) | Adds arr2 as columns to end of arr1
np.split(arr,3) | Splits arr into 3 sub-arrays
np.hsplit(arr,5) | Splits arr horizontally on the 5th index

#Indexing/slicing/subsetting#numpy數組索引、切片、取子集
arr[5] | Returns the element at index 5
arr[2,5] | Returns the 2D array element on index [2][5]
arr[1]=4 | Assigns array element on index 1 the value 4
arr[1,3]=10 | Assigns array element on index [1][3] the value 10
arr[0:3] | Returns the elements at indices 0,1,2 (On a 2D array: returns rows 0,1,2)
arr[0:3,4] | Returns the elements on rows 0,1,2 at column 4
arr[:2] | Returns the elements at indices 0,1 (On a 2D array: returns rows 0,1)
arr[:,1] | Returns the elements at index 1 on all rows
arr<5 | Returns an array with boolean values
(arr1<3) & (arr2>5) | Returns an array with boolean values
~arr | Inverts a boolean array
arr[arr<5] | Returns array elements smaller than 5

#Scalar Math#numpy數組數學運算
np.add(arr,1) | Add 1 to each array element
np.subtract(arr,2) | Subtract 2 from each array element
np.multiply(arr,3) | Multiply each array element by 3
np.divide(arr,4) | Divide each array element by 4 (returns np.nan for division by zero)
np.power(arr,5) | Raise each array element to the 5th power

#Vector Math#numpy向量計算
np.add(arr1,arr2) | Elementwise add arr2 to arr1
np.subtract(arr1,arr2) | Elementwise subtract arr2 from arr1
np.multiply(arr1,arr2) | Elementwise multiply arr1 by arr2
np.divide(arr1,arr2) | Elementwise divide arr1 by arr2
np.power(arr1,arr2) | Elementwise raise arr1 raised to the power of arr2
np.array_equal(arr1,arr2) | Returns True if the arrays have the same elements and shape
np.sqrt(arr) | Square root of each element in the array
np.sin(arr) | Sine of each element in the array
np.log(arr) | Natural log of each element in the array
np.abs(arr) | Absolute value of each element in the array
np.ceil(arr) | Rounds up to the nearest int
np.floor(arr) | Rounds down to the nearest int
np.round(arr) | Rounds to the nearest int

#Statistics#numpy中統計運算
np.mean(arr,axis=0) | Returns mean along specific axis
arr.sum() | Returns sum of arr
arr.min() | Returns minimum value of arr
arr.max(axis=0) | Returns maximum value of specific axis
np.var(arr) | Returns the variance of array
np.std(arr,axis=1) | Returns the standard deviation of specific axis
arr.corrcoef() | Returns correlation coefficient of array

4、Pandas速查手冊

相關焦點

  • Python數據分析:pandas讀取和寫入數據
    我的公眾號是關於自己在數據分析/挖掘學習過程中的一些技術和總結分享,文章會持續更新......繼續深入學習pandas相關操作,數據讀取寫入、分組、合併,轉換等等。前面一篇文章裡已經寫了關於描述性統計以及常用的基本操作。接下來的一段時間裡,我將陸續地去掌握並輸出。這篇文章是關於數據讀取與寫入的知識點。
  • 懂Excel輕鬆入門Python數據分析包pandas(二十七):IF函數代替者
    此系列文章收錄在:數據大宇宙 > 數據處理 > E-pd轉發本文並私信我"python",即可獲得Python資料以及更多系列文章(持續更新的)經常聽別人說 Python 在數據領域有多厲害,結果學了很長時間,連數據處理都麻煩得要死。
  • Python學習120課 pandas簡介kaggle下載數據及pandas讀取外部數據
    【每天幾分鐘,從零入門python編程的世界!】numpy的基本的東西我們學習差不多了,後面具體應用中遇到問題具體分析,然後去深入了解遇到的新的知識點就行。現在我們開始學習pandas,pandas一般用的更多,pandas是基於numpy去寫的。pandas是一個專門做數據結構和數據分析的庫。
  • 小白學數據小抄放送 Python,R,大數據,機器學習
    它提供了Python學習的必備包和一些有用的學習技巧等資源。 2. Python基礎小抄表 這張由Datacamp製作的小抄表覆蓋了所有Python數據科學需要的基礎知識。如果你剛開始用Python,可以留著這張做快速參考。背下這些小抄的代碼變量、數據類型函數、字符串操作、類型轉換、列表和常用操作。尤其是它列出了重要的Python包,給出了用於選擇並導入包的小抄代碼。
  • 小白學數據28張小抄放送 Python,R,大數據,機器學習
    Python基礎小抄表 這張由Datacamp製作的小抄表覆蓋了所有Python數據科學需要的基礎知識。如果你剛開始用Python,可以留著這張做快速參考。背下這些小抄的代碼變量、數據類型函數、字符串操作、類型轉換、列表和常用操作。尤其是它列出了重要的Python包,給出了用於選擇並導入包的小抄代碼。
  • Cheat sheet?
    Reader question:Please explain 「cheat sheet」 in this: 「I even brought a cheat sheet withA cheat sheet, you see, is a slip of paper on which are written answers for a test.
  • 值得收藏的 NumPy 小抄表(含主要語法、代碼)
    實現的科學計算的擴展程序庫,包括:3、用於整合C/C++和Fortran代碼的工具包;4、實用的線性代數、傅立葉變換和隨機數生成函數。numpnumpy和稀疏矩陣運算包scipy配合使用更加方便。NumPy(Numeric Python)提供了許多高級的數值編程工具,如:矩陣數據類型、矢量處理,以及精密的運算庫。專為進行嚴格的數字處理而產生。多為很多大型金融公司使用,以及核心的科學計算組織如:Lawrence Livermore,NASA用其處理一些本來使用C++,Fortran或Matlab等所做的任務。
  • Python模塊NumPy,Pandas,matplotlib的中文文檔
    今天比較忙所以不能寫長文了作為一名數據工程師需要熟練掌握python中的這些numpy,matplotlib,pandas,sklearn,seaborn,statsmodel.模塊但是由於這些模塊的文檔都是英文的可能一些英文不好的同學學起來會比較的困難,所以我從網上給大家找到一些中文的文檔
  • 懂Excel也能輕鬆入門Python數據分析包pandas(二):高級篩選(上)
    更多 Python 數據處理的乾貨,敬請關注!!!!系列文章:懂Excel就能輕鬆入門Python數據分析包pandas(一):篩選功能前言經常聽別人說 Python 在數據領域有多厲害,結果學了很長時間,連數據處理都麻煩得要死。
  • python數據科學系列:numpy入門詳細教程
    python數據科學基礎庫主要是三劍客:numpy,pandas以及matplotlib,每個庫都集成了大量的方法接口,配合使用功能強大。numpy:numerical python縮寫,提供了底層基於C語言實現的數值計算庫,與python內置的list和array數據結構相比,其支持更加規範的數據類型和極其豐富的操作接口,速度也更快num
  • 用R也可以跑Python了
    如果你主要從事數據分析、統計建模和可視化,R大概是你的不二之選。但如果你還想來搞點深度學習,整個自然語言處理,那你可還真得用Python。如果你處於交叉領域,很可能就需要兩種語言切換。」;conda_install(「r-reticulate」,「numpy」)如果「numpy」已經安裝,您不必再次安裝這個包。
  • 學習筆記,從NumPy到Scrapy,學習Python不能錯過這些庫
    一、核心庫與統計1.NumPynumpy(Numerical Python extensions)是一個第三方的Python包,用於科學計算。其前身是1995年就開始開發的一個用於數組運算的庫。經過了長時間的發展,基本上成了絕大部分Python科學計算的基礎包,當然也包括所有提供Python接口的深度學習框架。
  • python數據分析基礎之numpy
    支持高級大量的維度數組與矩陣運算,是學習數據挖掘的基礎,今天我們就來總結下numpy的一些基礎用法。首先,在講numpy之前,我先帶領大家預習下大學學習過的矩陣的基礎知識。1、矩陣的基本概念矩陣:由m×n個數排列成 的m行n列的數表,稱為m行n列矩陣。實矩陣:元素是實數的矩陣。復矩陣:元素是負數的矩陣。
  • Python數據分析|線性回歸
    Python數據分析學習筆記,今天分享下利用Python對業務進行數據預處理,並利用線性回歸進行數據預測。壹 數據導入Python下載及環境配置這裡就不贅述了哈,網上教程非常多,我們直接一開始就進入乾貨,打它一個開門見山。
  • Python數據分析利器,Pandas入門介紹,幫你便捷高效處理複雜數據
    關於Python的數據分析,當我們遇到的數據量小、數據結構簡單時,可以通過字典、列表等Python常見的數據結構來處理。但是當我們面對的大量數據以及複雜數據的局面時,就需要用一些專門用於數據分析的擴展庫來處理數據了。今天給大家介紹一個Python裡專門用來做數據分析和處理的擴展庫。
  • Linux命令cheat的安裝和使用
    大家好,今天周二,還是和往常一樣,沒有精神,每天坐在電腦前一坐就是一天,感覺身體也是一天不如一天了,不說這些,今天說一下Linux命令cheat, cheat 允許你在命令行中創建和查看交互式的速查表cheatsheet。它能幫助提醒 *nix 系統管理員他們經常使用但還沒頻繁到會記住的命令的選項,raksmart伺服器。
  • python數據分析——pandas導出數據合集
    導入pandas庫:import pandas as pd導入基礎數據:df=pd.read_excel('數據.xlsx')1.將DataFrame寫入csv\txt文件DataFrame.to_csv()常用參數:path_or_buf=None:輸出文件路徑,默認None
  • Python視頻教程網課編程零基礎入門數據分析網絡爬蟲全套Python...
    總目錄 零基礎全能篇(4套課程) 實用編程技巧進價(1套課程) 數據分析與挖掘(8套課程) 辦公自動化(3套課程) 機器學習與人工智慧(7套課程) 開發實戰篇(4套課程) 量化投資(2套課程) 網絡爬蟲(6套課程) 資料庫操作(1套課程) python
  • 乾貨| 請收下這份2018學習清單:150個最好的機器學習,NLP和Python...
    找到超過25個有關ML的「小抄」後,我寫一篇博文(https://unsupervisedmethods.com/cheat-sheet-of-machine-learning-and-python-and-math-cheat-sheets-a4afe4e791b6),裡面的資源都有超連結。
  • ...請收下這份2018學習清單:150個最好的機器學習,NLP和Python教程
    找到超過25個有關ML的「小抄」後,我寫一篇博文(https://unsupervisedmethods.com/cheat-sheet-of-machine-learning-and-python-and-math-cheat-sheets-a4afe4e791b6),裡面的資源都有超連結。