Gradio에서 표로 보기
실습 데이터
kospi
필요한 모듈 설치하기
google drive 연결하기
from google.colab import drive
drive.mount('/content/drive')
KOSPI 데이터 읽기
import numpy as np
import pandas as pd
df = pd.read_csv('/content/drive/MyDrive/Colab Notebooks/kospi.csv', sep=',', encoding="cp949")
df
Gradio에서 표로 표시하기
import gradio as gr
df = pd.read_csv('/content/drive/MyDrive/Colab Notebooks/kospi.csv', sep=',', encoding="cp949")
with gr.Blocks() as demo:
gr.DataFrame(df)
demo.launch()
특정 컬럼만 가져오기
import gradio as gr
df = pd.read_csv('/content/drive/MyDrive/Colab Notebooks/kospi.csv', sep=',', encoding="cp949")
c = ['Date', 'Close', 'Volume']
df = df[c]
with gr.Blocks() as demo:
gr.DataFrame(df)
demo.launch()
컬럼 이름 변경하기
import gradio as gr
df = pd.read_csv('/content/drive/MyDrive/Colab Notebooks/kospi.csv', sep=',', encoding="cp949")
c = ['Date', 'Close', 'Volume']
df = df[c]
df.rename(columns = {'Date':'날짜', 'Close':'종가', 'Volume':'거래량'}, inplace=True)
with gr.Blocks() as demo:
gr.DataFrame(df)
demo.launch()
최저값과 최고값 표시하기
import gradio as gr
df = pd.read_csv('/content/drive/MyDrive/Colab Notebooks/kospi.csv', sep=',', encoding="cp949")
c = ['Date', 'Close', 'Volume']
df = df[c]
df.rename(columns = {'Date':'날짜', 'Close':'종가', 'Volume':'거래량'}, inplace=True)
with gr.Blocks() as demo:
with gr.Row():
gr.Label(f"{df['종가'].min()}", label="최저점 지수")
gr.Label(f"{df['종가'].max()}", label="최고점 지수")
gr.DataFrame(df)
demo.launch()
소수점 반올림하기
import gradio as gr
df = pd.read_csv('/content/drive/MyDrive/Colab Notebooks/kospi.csv', sep=',', encoding="cp949")
c = ['Date', 'Close', 'Volume']
df = df[c]
df.rename(columns = {'Date':'날짜', 'Close':'종가', 'Volume':'거래량'}, inplace=True)
# 소수점 2자리로 반올림
df = df.round(2)
with gr.Blocks() as demo:
with gr.Row():
gr.Label(f"{df['종가'].min()}", label="최저점 지수")
gr.Label(f"{df['종가'].max()}", label="최고점 지수")
gr.DataFrame(df)
demo.launch()
최소와 최고값을 천단위로 표시하기
import gradio as gr
df = pd.read_csv('/content/drive/MyDrive/Colab Notebooks/kospi.csv', sep=',', encoding="cp949")
c = ['Date', 'Close', 'Volume']
df = df[c]
df.rename(columns = {'Date':'날짜', 'Close':'종가', 'Volume':'거래량'}, inplace=True)
# 소수점 2자리로 반올림
df = df.round(2)
with gr.Blocks() as demo:
with gr.Row():
gr.Label(f"{df['종가'].min():,}", label="최저점 지수")
gr.Label(f"{df['종가'].max():,}", label="최고점 지수")
gr.DataFrame(df)
demo.launch()
테이블 데이터를 천단위로 표시하기1
import gradio as gr
df = pd.read_csv('/content/drive/MyDrive/Colab Notebooks/kospi.csv', sep=',', encoding="cp949")
c = ['Date', 'Close', 'Volume']
df = df[c]
df.rename(columns = {'Date':'날짜', 'Close':'종가', 'Volume':'거래량'}, inplace=True)
# 소수점 2자리로 반올림
df = df.round(2)
with gr.Blocks() as demo:
with gr.Row():
gr.Label(f"{df['종가'].min():,}", label="최저점 지수")
gr.Label(f"{df['종가'].max():,}", label="최고점 지수")
#천단위 포멧으로 변경. 레이블 아래 쪽으로 이동 필요
df['종가'] = df['종가'].apply(lambda x: f"{x:,.2f}")
df['거래량'] = df['거래량'].apply(lambda x: f"{x:,.0f}")
gr.DataFrame(df)
demo.launch()
테이블 데이터를 천단위로 표시하기2
import gradio as gr
df = pd.read_csv('/content/drive/MyDrive/Colab Notebooks/kospi.csv', sep=',', encoding="cp949")
c = ['Date', 'Close', 'Volume']
df = df[c]
df.rename(columns = {'Date':'날짜', 'Close':'종가', 'Volume':'거래량'}, inplace=True)
# 소수점 2자리로 반올림
df = df.round(2)
#천단위 포멧으로 변경.
df['종가'] = df['종가'].apply(lambda x: f"{x:,.2f}")
df['거래량'] = df['거래량'].apply(lambda x: f"{x:,}")
with gr.Blocks() as demo:
with gr.Row():
close_float_list = df['종가'].replace({',': ''}, regex=True).astype(float)
gr.Label(f"{close_float_list.min():,.2f}", label="최저점 지수")
gr.Label(f"{close_float_list.max():,.2f}", label="최고점 지수")
gr.DataFrame(df)
demo.launch()
Pandas에서의 숫자 및 문자 변환
숫자(정수형) -> 문자
df['value'] = df['value'].apply(lambda x: f"{x:,}")
문자 -> 숫자(정수형)
df['value'] = pd.to_numeric(df['value'])