You are on page 1of 3

Documentation on NUMPY and PANDAS

numpy as the name suggests, is a package based on numerical methods in python.


Imported as
import numpy as np (meaning np can be used instead of numpy)

np.array():
numpy function to create an array from lists. Any number of lists can be send in as
arguments.

shape():
used to return the shape of the array created.

dtype():
returns the datatype of the members of the array.

zeros():
creates new numpy array with all zeroes.

ones():
all elements as 1

eye():
creates identity array/matrix.

arange(start,end,skip_value):
np.arange creates an array with values from start to end by skippind the value in
the third argument.

SCALAR OPERATIONS ON ARRAY

arrays can be scalarly


1. multiplied
2. exponentially multiplied
3. Subtracted
4. Reciprocated
5. Divided

ARRAY INDEXING:

Arrays can splitted the same way lists are splitted.


Values can also be manipulated using these indexes.
Values are passed by reference. Thus the mother array is modified everytime its
child arrays are modified.

copy():
creates a new copy of the array.

TWO DIMENSIONAL ARRAYS:

2d arrays can also be sliced the same way 1D arrays are sliced.

For eg:
slice1 = arr2d[0:2,0:2]

another way of accessing th rows is


arr2d[[0,1]]

UNIVERSAL ARRAY FUNCTIONS by NUMPY:


1. np.arange
2. np.sqrt
3. np.exp
4. np.add
5. np.maximum

SAVING AND LOADING ARRAYS

Arrays can be saved and loaded from the secondery memory.


To save single arrays
np.save('name',arr)
a new file named name.npy is created
np.load('name.npy')
loads the saved array with the 'name'

To save multiple arrays:


np.savez('name.npz',x=array1,y=array2)
TO load zip file
np.load('name.npz')

To save to textfile
np.savetxt('name.txt',array1,delimiter=',')
To load textfile
np.loadtxt('name.txt', delimiter=',')

STATISTICAL MATHEMATICAL PROCESSING OF ARRAYS:

matplotlib is a package used for plotting various functions and graphs in python.

from matplotlib pyplot is imported


*** import matplotlib.pyplot as plt

np.meshgrid()
assigns values to axes's by returning array values from its arguments.\

plt.imshow(function)
plots the function

plt.title("Title here")
Function to put the title of the graph
plt.colorbar()
to display the colorbar
plt.savefig('image_name.png')
to save the graph as an image in png format.

CONDITIONAL CLAUSE AND BOOLEAN OPERATIONS:

if x,y are integer arrays and cond is a boolean array then another integer array z
can be filed as

z = [a if c else b for a, cnd, b in zip(x,cond,y)]

or

no.where(cond,x,y)

STANDARD FUNCTIONS

sum(), mean(), std(), var()


any() //or operator
all() //and operator

sort() //to sort the array


unique() //returns the unique elements from the array
in1d([elemnts],array) //return whether each of the elements are present
in the array in the second argument

DATA MANUPULATION WITH PANDAS:

pandas is a strong package in python for data manupulation .

SERIES:
function used to create an object with the values in its arguments.

indexes can be customised using index=[] argument

Series can be converted to dictionery using to_dict() function

NaN values:
Not available values for indexes that doesnt have a value to assigned yet.

isnull()
notnull()

Serieses can be scalarly added.


Assigning names to Series,
series_name.name="name"
series_name.index.name="index_name"

DATAFRAMES:
package fro pandas

importes as
***from pandas import pandas

read.clipboard()
returns the object with the text copied in clipboard.

dataframe functions

.columns // returns only the columns


.head(int) // returns records from the head
.tail(int) // retunrs records from the end
.ix[int] // access rows in df

df['column_name'] // accessing values

/*End of documentation.*/

You might also like