...
Code Block |
---|
import pandas as pd header = pd.MultiIndex.from_product([['Semester1','Semester2'],['Maths','Science']]) d=([[12,45,67,56],[78,89,45,67],[45,67,89,90],[67,44,56,55]]) df = pd.DataFrame(d, index=['Alisa','Bobby','Cathrine','Jack'], columns=header) # stack the dataframe stacked_df=df.stack() # unstack the dataframe unstacked_df = stacked_df.unstack() # stack the dataframe of column at level 0 stacked_df_lvl=df.stack(level=0) # unstack the dataframe unstacked_df1 = stacked_df_lvl.unstack() |
Algorithms
A function checks if a given word is a palindrome
Code Block |
---|
def is_palindrome(word):
j = len(word)-1
i =0
while i<j and word[i].lower()==word[j].lower():
i+=1
j-=1
return (i>=j)
print(is_palindrome('Deleveled')) |