I’m using a CSV file and want to put the date data as it appears in the table directly on the x-axis of the graph, but the x-axis data in my graph is displayed incorrectly. Which part of my code could be wrong?
I have attached the table and the resulting graph as URL.
enter image description here
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns
def get_font_family():
import platform
system_name = platform.system()
if system_name == "Darwin":
font_family = "AppleGothic"
elif system_name == "Windows":
font_family = "Malgun Gothic"
return font_family
plt.rc("font", family=get_font_family())
df_price_index = pd.read_csv("/Users/sun/Downloads/품목별_소비자물가지수_품목성질별_2020100__20240626234308.csv", encoding='cp949')
df_price = df_price_index[df_price_index["품목별"] == "총지수"].copy() # 총지수 품목만 추출하여 복사본 생성
df_price["전년동월대비"] = df_price["데이터"].pct_change(periods=12) * 100 # 전년 동월 대비 증감률 계산
# print(df_price.dropna()) # 결측값 제거 후 데이터 출력
df_price_notnan = df_price.dropna()
print(df_price_notnan)
plt.figure(figsize=(10,4))
plt.plot(df_price_notnan['시점'], df_price_notnan['전년동월대비'], marker=".")
I’m a beginner, so I’m not sure which part is wrong.
New contributor
littleBoyyy is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.