Documente Academic
Documente Profesional
Documente Cultură
It is the fundamental package for scientific computing with Python. It contains various features including
these important ones:
A powerful N-dimensional array object
Sophisticated (broadcasting) functions
Tools for integrating C/C++ and Fortran code
Useful linear algebra, Fourier transform, and random number capabilities
Besides its obvious scientific uses, NumPy can also be used as an efficient multi-dimensional container of
generic data.
Arbitrary data-types can be defined using Numpy which allows NumPy to seamlessly and speedily
integrate with a wide variety of databases.
We will get a brief insight on all these basic operation which can be performed on Pandas DataFrame :
Creating a Pandas DataFrame
In the real world, a Pandas DataFrame will be created by loading the datasets from existing storage, storage
can be SQL Database, CSV file, and Excel file. Pandas DataFrame can be created from the lists, dictionary,
and from a list of dictionary etc. Dataframe can be created in different ways here are some ways by which
we create a dataframe:
Creating a dataframe using List: DataFrame can be created using a single list or a list of lists.
# import pandas as pd
import pandas as pd
# list of strings
lst = ['Geeks', 'For', 'Geeks', 'is',
'portal', 'for', 'Geeks']
Introduction
At the heart of a Numpy library is the array object or the ndarray object (n-dimensional array). You will
use Numpy arrays to perform logical, statistical, and Fourier transforms. As part of working with Numpy,
one of the first things you will do is create Numpy arrays. The main objective of this guide is to inform a
data professional, you, about the different tools available to create Numpy arrays.
There are three different ways to create Numpy arrays:
Numpy has built-in functions for creating arrays. We will cover some of them in this guide.
Creating a One-dimensional Array
First, let’s create a one-dimensional array or an array with a rank 1. arange is a widely used function to
quickly create an array. Passing a value 20 to the arange function creates an array with values ranging
from 0 to 19.
import Numpy as np
array = np.arange(20)
array
python
Output:
array([0, 1, 2, 3, 4,
5, 6, 7, 8, 9,
10, 11, 12, 13, 14,
15, 16, 17, 18, 19])
Python Arrays:
In this article, you’ll learn about Python arrays, difference between arrays and lists, and how and
when to use them with the help of examples.
Arrays are popular in most programming languages like Java, C/C++, JavaScript and so on. However, in
Python, they are not that common. When people talk about Python arrays, more often than not, they are
talking about Python lists. If you don't know what lists are, you should definitely check Python list article.
That being said, array of numeric values are supported in Python by the array module.
As you might have guessed from the above example, we need to import array module to create arrays. For
example:
Here, we created an array of float type. The letter 'd' is a type code. This determines the type of the array
during creation.
Q.5 Difference between LIST IN PYTHON vs NUMPY ARRAY in Python ?
Arrays and lists are both used in Python to store data, but they don't serve exactly the same purposes. They
both can be used to store any data type (real numbers, strings, etc), and they both can be indexed and
iterated through, but the similarities between the two don't go much further. The main difference between
a list and an array is the functions that you can perform to them. For example, you can divide an array by
3, and each number in the array will be divided by 3 and the result will be printed if you request it. If you
try to divide a list by 3, Python will tell you that it can't be done, and an error will be thrown.
x = array([3, 6, 9, 12])
x/3.0
print(x)
array([1, 2, 3, 4])
y = [3, 6, 9, 12]
y/3.0
print(y)
It's almost exactly like the first example, except you wouldn't get a valid output because the code would
throw an error.
It does take an extra step to use arrays because they have to be declared while lists don't because they are
part of Python's syntax, so lists are generally used more often between the two, which works fine most of
the time. However, if you're going to perform arithmetic functions to your lists, you should really be using
arrays instead. Additionally, arrays will store your data more compactly and efficiently, so if you're storing
a large amount of data, you may consider using arrays as well.