
지난 강의 기획서 초안 복사 후, 첫번째 파일 (market_trend.csv)첨부하고 캔버스로 엔터 눌렀더니 다음과 같은 코드가 나옵니다. 어떻게 해야할까요?
import pandas as pd
# Load the CSV file
file_path = '/mnt/data/market_trend.csv'
df = pd.read_csv(file_path)
# Display structure (info)
print("=== DataFrame Info ===")
print(df.info())
# Display first 5 rows
print("\n=== Top 5 Rows ===")
print(df.head())
# Attempt to calculate growth rate statistics
# Assuming there is a column related to growth rate
possible_growth_cols = [col for col in df.columns if 'growth' in col.lower() or 'rate' in col.lower()]
if possible_growth_cols:
growth_col = possible_growth_cols[0]
print(f"\nUsing column '{growth_col}' for growth rate calculations.")
print("Average Growth Rate:", df[growth_col].mean())
print("Maximum Growth Rate:", df[growth_col].max())
print("Minimum Growth Rate:", df[growth_col].min())
else:
print("\nNo obvious growth rate column found. Please check column names.")
CSV 파일을 분석하는 Python 스크립트를 캔버스에 생성했습니다.
해당 코드를 실행하면 다음을 확인할 수 있습니다:
데이터 구조(df.info())
상위 5개 행(df.head())
성장률 관련 컬럼 자동 탐색 후
평균 성장률
최대 성장률
최소 성장률
만약 성장률 컬럼명이 명확하다면(예: growth_rate, annual_growth 등), 그 컬럼명을 지정해 보다 정확하게 계산하도록 수정해 드릴 수 있습니다.
