In [1]:
import numpy as np
In [2]:
from random import randint,randrange
In [4]:
for x in range(10,50):
print(randrange(15))
In [7]:
def mynewfunction(x,y):
z=x**2+3*x**2*y+20*y**2
print(z)
In [9]:
mynewfunction(1,3)
In [11]:
mynewfunction(10,30)
In [14]:
def mybadfunction(x,y):
z=x**2+3*x**2*y+20*y**2
return(z)
In [15]:
mybadfunction(1,1)
Out[15]:
In [16]:
scores=(23,46,69,7,5)
In [17]:
type(scores)
Out[17]:
In [22]:
sc=(46,45)
In [23]:
type(sc)
Out[23]:
In [24]:
scores+sc
Out[24]:
In [25]:
favourite_movie2={'micky mouse':'steamboat willie','vijay':'slumdog millionaire','john':'passion of christ','donald':'arthur'}
In [26]:
type(favourite_movie2)
Out[26]:
In [29]:
favourite_movie2['vijay']
Out[29]:
In [30]:
import re
In [31]:
names=["Agung","Deja", "Brahm","Nathan","Ratna","Naufal","Scholly","Siska","Bintang","Sandra"]
In [32]:
for name in names:
print (re.search(r'(an)',name))
In [34]:
for name in names:
print (bool(re.search(r'(an)',name)))
In [35]:
import re
import numpy as np
In [36]:
numlist=["$60000","$80,000","30,000",70000,"55000 "]
In [37]:
enumerate?
In [38]:
re.sub(r"([$,])","",str("$60000"))
Out[38]:
In [39]:
int('60000')
Out[39]:
In [40]:
for i,value in enumerate(numlist):
numlist[i]=re.sub(r"([$,])","",str(value))
numlist[i]=int(numlist[i])
print(numlist)
In [41]:
numlist
Out[41]:
In [42]:
import numpy as np
In [43]:
np.mean(numlist)
Out[43]:
In [44]:
from datetime import datetime
In [46]:
datetime_object = datetime.strptime('June/17/2016 1:33PM', '%B/%d/%Y %I:%M%p')
In [47]:
datetime_object
Out[47]:
In [48]:
date_object2=datetime.strptime("12dec-2007","%d%b-%Y")
In [49]:
date_object2
Out[49]:
In [53]:
a=date_object2-datetime_object
In [54]:
a
Out[54]:
In [58]:
a.days
Out[58]:
In [60]:
a.days/30
Out[60]:
In [61]:
from dateutil import relativedelta
In [67]:
r =- relativedelta.relativedelta(date_object2, datetime_object)
In [68]:
r.months
Out[68]:
In [69]:
r.years
Out[69]:
In [71]:
def f(x):return x**3+3*x**2
In [72]:
f(1)
Out[72]:
In [73]:
type(f)
Out[73]:
In [74]:
g=lambda x:x**3+3*x**2
In [75]:
g(10)
Out[75]:
In [76]:
type(g)
Out[76]:
In [77]:
import pandas as pd
In [78]:
import os as os
In [81]:
diamonds=pd.read_csv("C:\\Users\\KOGENTIX\\Desktop\\training\\BigDiamonds.csv\\BigDiamonds.csv")
In [84]:
diamonds.info()
In [96]:
adult=pd.read_csv("https://archive.ics.uci.edu/ml/machine-learning-databases/adult/adult.data",header=None)
In [98]:
#pd.read_csv?
'''this is
a multiple
line comment
'''
Out[98]:
In [99]:
adult.head()
Out[99]:
In [101]:
adult.columns
Out[101]:
In [102]:
adult.columns=["age ",
"workclass ",
"fnlwgt",
"education ",
"education-num",
"marital-status",
"occupation",
"relationship",
"race",
"sex",
"capital-gain",
"capital-loss",
"hours-per-week",
"native-country",
"income",
]
In [103]:
adult.head()
Out[103]:
In [105]:
wb=pd.read_json("C:\\Users\\KOGENTIX\\Desktop\\training\\world_bank.json",lines=True)
In [106]:
wb.head()
Out[106]:
In [107]:
wb.columns
Out[107]:
In [108]:
type(adult)
Out[108]:
In [109]:
adult.values
Out[109]:
In [110]:
b=adult.values
In [111]:
type(b)
Out[111]:
In [112]:
len(b)
Out[112]:
In [115]:
np.arange(len(b))
Out[115]:
In [116]:
c=["age ",
"workclass ",
"fnlwgt",
"education ",
"education-num",
"marital-status",
"occupation",
"relationship",
"race",
"sex",
"capital-gain",
"capital-loss",
"hours-per-week",
"native-country",
"income",
]
In [118]:
b
Out[118]:
In [119]:
c
Out[119]:
In [121]:
d=np.arange(len(b))
In [122]:
d
Out[122]:
In [123]:
adult3=pd.DataFrame(data=b, # values
index=d, # 1st column as index
columns=c) # 1st row as the column names
In [124]:
adult3.head()
Out[124]:
In [ ]: