Perhaps the nicest thing about numpy is its handling of complicated 2D datasets. It has its own array types which overload the indexing operators. Note the difference in the below from the standard [1d][2d] notation:
import numpy
data = numpy.int_([
[1,2,3,4,5],
[10,20,30,40,50],
[100,200,300,400,500]
])
print(data[0,0]) # 1
print(data[1:3,1:3]) # [[20 30][200 300]]
On a standard list, data[1:3][1:3] wouldn't work; at best data[1:3][0][1:3] would give you [20][30]
Numpy operations
You can additionally do maths on the arrays, including matrix manipulation.
import numpy
data = numpy.int_([
[1,2,3,4,5],
[10,20,30,40,50],
[100,200,300,400,500]
])
print(data[1:3,1:3] - 10) # [[10 20],[190 290]]
print(numpy.transpose(data[1:3,1:3])) # [[20 200],[30 300]]
Pandas data focuses around DataFrames, 2D arrays with addition abilities to
name and use rows and columns.
df = pandas.DataFrame(
data, # numpy array from before.
index=['i','ii','iii'],
columns=['A','B','C','D','E'])
print (data['A'])
print(df.mean(0)['A'])
print(df.mean(1)['i'])
Prints:
i 1
ii 10
iii 100
Name: A, dtype: int32
37.0
3.0