Reduce the amount of data from chart plot matplotlib
Hello I have this code below where I'm supposed to display the plot of only 15 amounts of data from 'Apps' column and 'Total Downloaded' column. The thing is there's total 100 rows which I want to reduce column 'Apps' and 'Total Downloaded' to 15 and plot them. How do I do that?
import pandas as pd
import matplotlib.pyplot as plt
data = pd.read_excel("C:\\users\\HP\\Documents\\Datascience task\\Apps.xlsx")
data = data.rename(columns={'Total Downloads (Per Thousand)': 'Total Downloaded'})
apps = sorted(data['Apps']) # * Display only 15 apps
total_downloads = sorted(data['Total Downloaded']) # * Display 15 data of total downloaded
# * Plot the amount of downloaded app and thier name
plt.plot(total_downloads,apps) # * X , Y
plt.xlabel('Total Downloaded (Per Thousand)')
plt.ylabel("Apps")
data
Solution 1:
If need first 15 values:
data1 = data.rename(columns={'Total Downloads (Per Thousand)': 'Total Downloaded'}).head(15)
If need first top15 by Total Downloaded
use:
data1 = (data.rename(columns={'Total Downloads (Per Thousand)': 'Total Downloaded'})
.nlargest(15, 'Total Downloaded'))
And then sorting is not necessary, use:
plt.plot(data1['Total Downloaded'],data1['Apps']) # * X , Y
plt.xlabel('Total Downloaded (Per Thousand)')
plt.ylabel("Apps")