Basic of Python
Basic of Python
In [ ]:
planet = "Earth"
diameter = 12742
print('The diameter of {} is {} kilometers. '. format(planet, diameter))
The diameter of Earth is 12742 kilometers.
d = {'k1':[1,2,3,{'tricky':['oh','man','inception',{'target':
[1,2,3,'hello']}]}]}
In [ ]:
d = {'k1':[1,2,3,{'tricky':['oh','man','inception',{'target':
[1,2,3,'hello']}]}]}
d['k1'][3]['tricky'][3]['target'][3]
Out[ ]:
'hello'
Numpy
import numpy as np
array([0., 0., 0., 0., 0., 0., 0., 0., 0., 0.])
array([5., 5., 5., 5., 5., 5., 5., 5., 5., 5.])
7. Concatenate a and b
import pandas as pd
In [ ]:
#initialize data
data=[['dillip','cse',80],['dhana','cse',90]]
df=pd.DataFrame(data,columns=['Name','Dept','marks'])
#print df
df
Out[ ]:
0 dillip cse 80
1 dhana cse 90
import pandas as pd
c=pd.date_range("01-01-2023","10-02-2023")
d=pd.Series(c)
print("The series of dates from 1st Jan, 2023 to 10th Feb, 2023")
d
The series of dates from 1st Jan, 2023 to 10th Feb, 2023
Out[ ]:
0 2023-01-01
1 2023-01-02
2 2023-01-03
3 2023-01-04
4 2023-01-05
...
270 2023-09-28
271 2023-09-29
272 2023-09-30
273 2023-10-01
274 2023-10-02
Length: 275, dtype: datetime64[ns]
lists = [[1, 'aaa', 22], [2, 'bbb', 25], [3, 'ccc', 24]]
In [ ]:
import pandas as pd
lists = [[1, 'aaa', 22], [2, 'bbb', 25], [3, 'ccc', 24]]
df=pd.DataFrame(lists)
#print df
df
Out[ ]:
0 1 2
0 1 aaa 22
bb
1 2 25
b
2 3 ccc 24