import pandas as pd
import matplotlib.pyplot as plt
from matplotlib import style
style.use("fivethirtyeight")
dictionary = {"Rank": [3, 2, 4, 5, 6], "Name": ["Tanu", "Ashika", "Ashwin", "Mohit", "Sourabh"], "Age": [23, 24, 22, 18, 9], "Weight": [69, 72, 65, 70, 40], "Occupation": ["Student", "Working", "Working", "Student", "Student"]}
df = pd.DataFrame(dictionary)
# Slicing the dataframe
df.head(3)
Rank | Name | Age | Weight | Occupation | |
---|---|---|---|---|---|
0 | 3 | Tanu | 23 | 69 | Student |
1 | 2 | Ashika | 24 | 72 | Working |
2 | 4 | Ashwin | 22 | 65 | Working |
df.tail(1)
Rank | Name | Age | Weight | Occupation | |
---|---|---|---|---|---|
4 | 6 | Sourabh | 9 | 40 | Student |
dictionary1 = {"Rank": [1], "Name": ["Tilo"], "Age": [80], "Weight": [80], "Occupation": ["Kitchen Queen"] }
df1 = pd.DataFrame(dictionary1)
# Concatenating the two dataframes (df, df1)
df_row = pd.concat([df, df1])
df_row
Rank | Name | Age | Weight | Occupation | |
---|---|---|---|---|---|
0 | 3 | Tanu | 23 | 69 | Student |
1 | 2 | Ashika | 24 | 72 | Working |
2 | 4 | Ashwin | 22 | 65 | Working |
3 | 5 | Mohit | 18 | 70 | Student |
4 | 6 | Sourabh | 9 | 40 | Student |
0 | 1 | Tilo | 80 | 80 | Kitchen Queen |
# To set the first as Rank
df_row.set_index("Rank", inplace = True)
# To sort the data Rank in the ascending order
df_row.sort_values(by=['Rank'])
Name | Age | Weight | Occupation | |
---|---|---|---|---|
Rank | ||||
1 | Tilo | 80 | 80 | Kitchen Queen |
2 | Ashika | 24 | 72 | Working |
3 | Tanu | 23 | 69 | Student |
4 | Ashwin | 22 | 65 | Working |
5 | Mohit | 18 | 70 | Student |
6 | Sourabh | 9 | 40 | Student |
df_row.plot()
plt.show()