import pandas as pd df = pd.read_excel('남북한발전전력량.xlsx', engine='openpyxl') df_ns = df.iloc[[0, 5], 3:] # 남한, 북한 발전량 합계 데이터만 추출 df_ns.index = ['South','North'] # 행 인덱스 변경 df_ns.columns = df_ns.columns.map(int) # 열 이름의 자료형을 정수형으로 변경 # 행, 열 전치하여 히스토그램 그리기 tdf_ns = df_ns.T tdf_ns.plot(kind='hist')
코랩에서는 잘 돌아가는데 쥬피터 노트북에서는 TypeError: no numeric data to plot라는 에러가 뜨며 돌아가지 않는다.
# 행, 열 전치하여 히스토그램 그리기 tdf_ns = df_ns.T tdf_ns['North'] = pd.to_numeric(tdf_ns['North']) tdf_ns['South'] = pd.to_numeric(tdf_ns['South']) tdf_ns.plot(kind='hist')
# 행, 열 전치하여 히스토그램 그리기 tdf_ns = df_ns.T tdf_ns = tdf_ns.apply(pd.to_numeric) # object → 숫자형으로 변경 tdf_ns.plot(kind='hist')