Chapter 6 Exercises after class
Program question
Answer:
import pandas as pd
stock_data = pd.DataFrame({'stock code':['000609','000993','002615',
'000795','002766','000971',
'000633','300173','300279','000831'],
'Securities Abbreviation': ['Zhongdi Investment','Mindong Power','Hals',
'Innova', 'Soling Shares', 'Gaosheng Holdings',
'Alloy Investment', 'Wisdom Songde', 'Hejing Technology', 'Minmetals Rare Earth'],
'Latest price': [4.80,4.80,5.02,3.93,6.78,
3.72,4.60,4.60,5.81,9.87],
'Increase or decrease%': [10.09,10.09,10.09,10.08,
10.06,10.06,10.06,10.05,10.05,10.04]})
print(stock_data)
Answer:
import matplotlib.pyplot as plt
%matplotlib inline
plt.rcParams['font.sans-serif']=['SimHei'] # Display Chinese labels normally
plt.rcParams['axes.unicode_minus']=False # Normal display negative sign
x_axis = stock_data['stock abbreviation']
y_axis = stock_data['latest price']
plt.bar(x_axis, y_axis)
# Save it first, if it is used after the show() function, the saved picture will be a blank picture
plt.savefig(r"C:\Users\admin\Desktop\shares_bar.png")
plt.show()