📜  Pandas VS NumPy 的区别

📅  最后修改于: 2021-09-12 10:56:45             🧑  作者: Mango

熊猫 是一个用Python语言编写的开源、BSD 许可的库。 Pandas提供高性能、快速、易于使用的数据结构和数据分析工具,用于处理数值数据和时间序列。 Pandas建立在numpy之上,并使用PythonCythonC等语言编写。在 Pandas 中,我们可以从各种文件格式导入数据,如JSON、SQL、Microsoft Excel等。

例子:

Python3
# Importing pandas library
import pandas as pd
  
# Creating and initializing a nested list
age = [['Aman', 95.5, "Male"], ['Sunny', 65.7, "Female"],
       ['Monty', 85.1, "Male"], ['toni', 75.4, "Male"]]
  
# Creating a pandas dataframe
df = pd.DataFrame(age, columns=['Name', 'Marks', 'Gender'])
  
# Printing dataframe
df


Python3
# Importing Numpy package
import numpy as np
  
# Creating a 3-D numpy array using np.array()
org_array = np.array([[23, 46, 85],
                      [43, 56, 99],
                      [11, 34, 55]])
  
# Printing the Numpy array
print(org_array)


输出:

麻木 是Python的基础库,用于执行科学计算。它提供了高性能的多维数组和处理它们的工具。 A N umpy阵列是由正整数的元组索引(同一类型)值的网格,numpy的阵列的速度快,容易理解,并为用户提供到跨阵列执行计算的权利。

例子:

蟒蛇3

# Importing Numpy package
import numpy as np
  
# Creating a 3-D numpy array using np.array()
org_array = np.array([[23, 46, 85],
                      [43, 56, 99],
                      [11, 34, 55]])
  
# Printing the Numpy array
print(org_array)

输出:

[[23 46 85]
[43 56 99]
[11 34 55]]

Pandas VS NumPy 差异表

 

PANDAS

NUMPY

1 When we have to work on Tabular data, we prefer the pandas module. When we have to work on Numerical data, we prefer the numpy module.
2 The powerful tools of pandas are Data frame and Series. Whereas the powerful tool of numpy is Arrays.
3 Pandas consume more memory. Numpy is memory efficient.
4 Pandas has a better performance when number of rows is 500K or more. Numpy has a better performance when number of rows is 50K or less.
5 Indexing of the pandas series is very slow as compared to numpy arrays. Indexing of numpy Arrays is very fast.
6 Pandas offers 2d table object called DataFrame. Numpy is capable of providing multi-dimensional arrays.