How to Download and Visualize Kweichow Moutai Stock Data with Python
This guide shows how to download historical Kweichow Moutai stock data from NetEase Finance as a CSV file, handle encoding issues, and use Python's pandas and matplotlib libraries to filter the data and create both volume and OHLC line charts for a selected month.
NetEase Finance provides a downloadable CSV file containing the historical trading data of Kweichow Moutai (贵州茅台) stock, as illustrated in Figure 1.
By clicking the “Download Data” hyperlink, a dialog (Figure 2) appears; after confirming the selection, the CSV file can be saved.
CSV (Comma‑Separated Values) is a plain‑text format commonly used for data exchange between spreadsheets and databases. It can be opened with a text editor or Excel, but Excel may alter data formats (e.g., leading zeros) and uses GBK encoding on Windows, so saving the file with the GBK charset avoids garbled characters.
The first example plots the daily trading volume for March 2021. The code (chapter6/ch6.2.6.py) reads the Excel file, filters rows where the date is between 2021‑03‑01 and 2021‑04‑01, sorts by date, and draws a line chart of Volume versus Date:
# coding=utf-8
# 代码文件:chapter6/ch6.2.6.py
import matplotlib.pyplot as plt
import pandas as pd
plt.rcParams['font.family'] = ['SimHei'] # set Chinese font
plt.rcParams['axes.unicode_minus'] = False # display minus sign correctly
plt.figure(figsize=(15, 5))
f = r'data\股票的历史交易数据.xlsx'
df = pd.read_excel(f)
df2 = df.query("Date >= '2021-03-01' and Date < '2021-04-01'").sort_values(by='Date') # ① filter and sort
plt.plot(df2['Date'], df2['Volume']) # ② draw volume line
plt.title('贵州茅台股票')
plt.ylabel('成交量')
plt.xlabel('交易日期')
plt.xticks(rotation=40)
plt.show()Explanation: line ① selects the March‑2021 records and orders them by date; line ② draws the volume line.
The second example creates an OHLC line chart for the same period, displaying opening, highest, lowest, and closing prices with legends. The code (chapter6/ch6.2.7.py) adds multiple plt.plot calls with the label argument:
# coding=utf-8
# 代码文件:chapter6/ch6.2.7.py
import matplotlib.pyplot as plt
import pandas as pd
plt.rcParams['font.family'] = ['SimHei']
plt.rcParams['axes.unicode_minus'] = False
plt.figure(figsize=(15, 5))
f = r'data\股票的历史交易数据.xlsx'
df = pd.read_excel(f)
df2 = df.query("Date >= '2021-03-01' and Date < '2021-04-01'").sort_values(by='Date')
plt.title('贵州茅台股票历史OHLC折线图')
plt.plot(df2['Date'], df2['Open'], label='开盘价') # ①
plt.plot(df2['Date'], df2['High'], label='最高价')
plt.plot(df2['Date'], df2['Low'], label='最低价')
plt.plot(df2['Date'], df2['Close'], label='收盘价') # ②
plt.ylabel('成交量')
plt.xlabel('交易日期')
plt.xticks(rotation=40)
plt.show()Explanation: the four plt.plot calls draw lines for Open, High, Low, and Close prices; the label parameter defines the legend entries.
With these scripts, you can quickly visualize a month’s worth of Kweichow Moutai stock trading data, gaining an intuitive view of volume trends and price movements.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
