Tuesday, June 7, 2022

Plotting Pandas Dataframe been sorted by coulmn of date type on F36

Both columns on the plot are not of numeric type, however directives

plt.plot(dfs['AdmissionDate'], dfs['Name'])
plt.xticks(rotation='vertical')
plt.show() 

allow to plot desired picture via standard mathplotlib commands

(.env) boris@boris-All-Series:~/MATPLOTLIBSR/TENSOR$ cat SortedPandasD1.py

# importing package
import pandas as pd
import matplotlib.pyplot as plt
 
# Creating a dataframe that stores records of students taking admission in a college
data = pd.DataFrame({'AdmissionDate': ['2021-01-25','2021-01-22','2021-01-20',
              '2021-01-18','2021-01-22','2021-01-17','2021-01-21'],
              'StudentID': [7,5,3,2,6,1,4],
              'Name': ['Ram','Shyam','Mohan','Sohan','Lucky','Abhinav','Danny'],
              'Stream':['CSE','ECE','Civil','Mechanical','CSE','IT','EEE']
                   })
# Checking dataframe
print(data)
print('\n')

dfs = data.sort_values(by='AdmissionDate', ascending=True)
print(dfs)

plt.plot(dfs['AdmissionDate'], dfs['Name'])
plt.xticks(rotation='vertical')

plt.show()