Question: Write a function that decides a suitable number format based on the data. ( 1 5 % ) - In the parameter list, it

Write a function that decides a suitable number format based on the data. (15\%)
- In the parameter list, it supplies a two-column dataframe and the output filename.
- Create the bar plot for dataframe.
- Use the second class label for the title of the plot
- Display the values in the first class label as the x-axis labels
- Display the number, with 2 significant figures, on top of the bar
- Decide the unit of each bar based on the value
- When the value is greater than or equal to \(1,000,000\), use \( M \)
- When the value is between 999,999 and 1000, use k
- Otherwise, use its original unit
- Save the plots as the specified output file. Do not show the plots.
- You can assume all the numbers are integers.
This problem is aboul a bar chart.
Code:
```
# Problem 4
import pandas as pd
def problem_4(df, output="q4.jpg"):
# write your logic here
plt.savefig(output) # do not show the plt
```
Execution:
```
data = pd.DataFrame({"Name": ["Amy", "Bob", "Cat"],
"Balance": [876,4320,43204320]})
problem_4(data)
```
q4.jpg:
Write a function that decides a suitable number

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!