Professional Documents
Culture Documents
read_excel()
df['Type'].unique()
df[df['Type']=='BASE]
df.sort_values(by='Type',asc=False)
df.sort_values(by='Type',asc=False).head(n=5)
df['TypeD'].mean()
df['TypeD'].max()
df['TypeD'].min()
df.to_excel()
df.info()
df.Income = df.Income.fillna(0)
df['Education'].value_counts().to_frame()
u = list(df['Marital_Status'].unique())
u.sort()
u
df[['Education','Marital_Status']] =
df[['Education','Marital_Status']].astype('category')
df['Dt_Customer'] = pd.to_datetime(df['Dt_Customer'])
df[['Education','Marital_Status', 'Dt_Customer']].info()
df.describe(include='category')
pd.options.display.float_format = '{:.1f}%'.format
ed = df['Education'].value_counts(normalize=True)*100
ed
pd.crosstab(df['Education'],
df['Marital_Status'], normalize=True
)*100
pd.crosstab(df['Education'],
df['AcceptedCmp1'], normalize=True, margins=True, margins_name="Total"
)*100
pd.options.display.float_format = '{:.2f}'.format
df.pivot_table(index= "Education", columns = 'Marital_Status', values =
'AcceptedCmp1', aggfunc = "sum")
LLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLL
LLLLLLLLLLLLLLLLLLLL
QQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQ
QQQQQQQQQQQQQQQQQQQQQQQ
import sys
def bubble_sort(arr):
# This function will sort the array in non-decreasing order.
n = len(arr)
#Traverse through all the array elements
for i in range(n):
# The inner loop will run for n-i-1 times as the
# last i elements are already in place.
for j in range(0, n-i-1):
# Swap if the present element is greater than the
# next element.
if arr[j] > arr[j+1]:
temp = arr[j]
arr[j] = arr[j+1]
arr[j+1] = temp
return arr
# main code
if __name__=='__main__':
arr = [2, 1, 9, 3, 7, 5, 6, 4, 8, 0]
print("Sorted array: ")
print(bubble_sort(arr))
Output
Sorted array:
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
def insertion_sort(arr):
# This function will sort the array in non-decreasing order.
n = len(arr)
# After each iteration first i+1 elements are in sorted order.
for i in range(1, n):
key = arr[i]
j = i-1
# In each iteration shift the elements of arr[0..i-1],
# that are greater than key, to one position ahead
# of their current position
while j >= 0 and key < arr[j]:
arr[j+1] = arr[j]
j -= 1
arr[j+1] = key
return arr
# main code
if __name__=='__main__':
arr = [24, 17, 66, 33, 72, 47, 68, 41, 105, 30]
print("Sorted array: ")
print(insertion_sort(arr))
def selection_sort(arr):
# This function will sort the array in non-decreasing order.
n = len(arr)
#The outer loop will run for n times.
for i in range(n):
min_index = i
# The inner loop will run for n-i-1 times as the
# first i elements are already in sorted.
for j in range(i+1, n):
# Compare if the present element is smaller than the
# element present at min_index in the array. If yes
# store the index of the present element in min-index.
if arr[min_index] > arr[j]:
min_index = j
# Swap the ith element with the smallest element in the
# unsorted list i.e. arr[min_index}].
if i != min_index:
temp = arr[i]
arr[i] = arr[min_index]
arr[min_index] = temp
return arr
# main code
if __name__=='__main__':
arr = [21, 15, 96, 37, 72, 54, 68, 41, 85, 30]
print("Sorted array: ")
print(selection_sort(arr))
Output
Sorted array:
[15, 21, 30, 37, 41, 54, 68, 72, 85, 96]
Python program to implement linear search
import sys
return (position)
# main code
if __name__=='__main__':
# main code
if __name__=='__main__':
l = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
num = 6
found = binary_search(l, num)
if found[0]:
print('Number %d found at position %d'%(num, found[1]+1))
else:
print('Number %d not found'%num)
Output
Number 6 found at position 7
return arr
def main():
#input format is described below
n, m, s = map(int, input().split())
edges = {}
for i in range(n):
edges[i] = []
for i in range(m):
a, b = map(int, input().split())
edges[a] += [b]
edges[b] += [a]
for i in range(n):
edges[i].sort()
arr = bfs(n, edges, s)
print(*arr)
if __name__ == '__main__':
main()
Input
Input format:
0 1 7 2 6 8 3 5 4
def reverse_by_sort(string):
'''
This function is used to reverse any string
by reversed() method.
'''
string = list(string)
rev_str = ''
for i in reversed(string):
rev_str += i
return rev_str
if __name__=='__main__':
size = 11
stack = [0]*size
string = 'Includehelp'
top = -1
print('\nUsing Stack')
print('\n\nUsing sort()')
print('Reversed string = %s' % reverse_by_sort(string))
Output
Original String = Includehelp
Using Stack
Reversed String = plehedulcnI
Using sort()
Reversed string = plehedulcnI