2a.pandas - Series
2a.pandas - Series
Pandas - Series
In [2]:
# PANDAS
# it is a python package providing fast, flexible and Expressive data structures design
# pandas is top of numpy
#Series(data,index=index)
In [1]:
# Creating a series from ndarray
import pandas as pd
import numpy as np
In [ ]:
pd.read_csv
In [2]:
test = np.array(['s','o','c','i','a','l'])
test
In [3]:
s = pd.Series(test)
Out[3]: 0 s
1 o
2 c
3 i
4 a
5 l
dtype: object
In [1]:
x= 2
y = 3
z = x+y
print(z)
a = z+ 2
Out[1]: 7
In [3]:
test = np.array(['s','o','c','i','a','l'])
s = pd.Series(test,index = [1,2,3,4,5,6])
Out[3]: 1 s
2 o
3 c
4 i
5 a
6 l
dtype: object
In [6]:
# Dict
test = {1:'a',2:'b'}
s = pd.Series(test)
Out[6]: 1 a
2 b
dtype: object
In [6]:
# Scalar
# if the data have repeated value then we have to match the index ( so index value will
x = pd.Series(2,index=[0,1,2])
Out[6]: 0 2
1 2
2 2
dtype: int64
In [7]:
# Series Indexing
s = pd.Series([1,2,3,4,5,6],index = ['s','o','c','i','a','l'])
Out[7]: s 1
o 2
c 3
i 4
a 5
l 6
dtype: int64
In [8]:
s['a']
Out[8]: 5
In [9]:
s['o']
Out[9]: 2
In [10]:
s['i']
Out[10]: 4
In [ ]:
In [ ]: