Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

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()


MatPlotLib

Spot graph by age and score by MapPlotLib

Below code shows a graph displaying multiple spots by age and score stored in a pandas data frame.

Code Block
languagepy
import pandas as pd
from matplotlib import pyplot as plt
  
# Create a DataFrame
d = {
    'Name':['Alisa','Bobby','jodha','jack','raghu','Cathrine',
    'Alisa','Bobby','kumar','Alisa','Alex','Cathrine'],
    'Age':[26,24,23,22,23,24,26,24,22,23,24,24],
  
    'Score':[85,63,55,74,31,77,85,63,42,62,89,77]
}
  
df = pd.DataFrame(d,columns=['Name','Age','Score'])
 
plt.plot(df['Age'], df['Score'], 'ro')
plt.xlabel('Age')
plt.ylabel('Score')
plt.title('Experiment Result')
plt.show()

Result

Image Added

Algorithms

Palindrome number - Determine whether an integer is a palindrome

...