[엑셀과 함께 춤을] M365 코파일럿 챗을 사용해 보자

일단 코파일럿 챗 (Web) 을 사용합시다

image


탐색기에서 파일을 드래그앤 드롭하고, 다른 말을 하지 않고 그대로 전송해 보겠습니다.

image


뭔가 파일을 읽어서 보여줍니다.

내용을 뜯어보면 시트들의 내용을 전부 살펴보고 전체적인 맥락을 파악해 말해줍니다.

image


엑셀 파일을 주면 코파일럿이 코드 인터프리터를 사용하는 것을 알고 있습니다.

이때 쓰기 좋은 프롬프트가 있습니다. “방금 사용한 코드를 알려주세요”  입니다.

보여주는 코드를 보니 타입스크립트로 파일을 읽어들이는 군요. 그냥 파일을 통째로 읽어들이는 군요.

image

fetch_file({
  doc_name: "뭔가통합 2.xlsx"
})

이 엑셀 파일은 동일한 포맷의 시트를 여러개 가지고 있습니다. 시트 목록을 알려 달라고 해 봅시다.

잘 보여주네요.

image


답변의 Analysis 를 클릭하면 수행한 코드를 바로 볼 수 있습니다.

파이썬으로 pandas 라이브러리를 사용한 것을 볼 수 있습니다. 엑셀 파일의 시트 목록을 불러서 바로 보여주지요.

image

import pandas as pd

# Load the Excel file
excel_file = pd.ExcelFile('뭔가통합 2.xlsx')

# Get the sheet names
sheet_names = excel_file.sheet_names

# Print the sheet names
print("Sheet names in the Excel file are:", sheet_names)

이제 조금 더 가봅시다. 각 시트에 있는 같은 항목의 내용을 모아서 보여달라고 해봅니다.

잘 해줍니다.

image


코드를 열어서 보면, 제가 알려준 ‘한글 프롬프트’ 를 컬럼으로 사용해서 쿼리하네요.

그런데 코드의 내용을 보면 pandas 라이브러리 외에도 openpyxl 라이브러리도 같이 사용하는 것을 볼 수 있습니다.

import pandas as pd

# Load the Excel file
file_path = '뭔가통합 2.xlsx'
xls = pd.ExcelFile(file_path)

# Initialize a dictionary to store prompts from each sheet
prompts = {}

# Iterate through each sheet and extract '한글 프롬프트' column
for sheet_name in xls.sheet_names:
    df = pd.read_excel(file_path, sheet_name=sheet_name, engine='openpyxl')
    if '한글 프롬프트' in df.columns:
        prompts[sheet_name] = df['한글 프롬프트'].tolist()

# Print the extracted prompts
for sheet, prompt_list in prompts.items():
    print(f"Sheet: {sheet}")
    for prompt in prompt_list:
        print(f"- {prompt}")

코파일럿과의 대화는 이전 맥락을 알고 있기 때문에 이런 식으로 물어보는 것도 가능하겠죠

“네번째 시트의 내용을 표로 보여줘요”

image


코드를 보면 계속 그렇게 동작하고 있습니다.

import pandas as pd

# Load the Excel file
file_path = '뭔가통합 2.xlsx'
xls = pd.ExcelFile(file_path)

# Extract the fourth sheet
sheet_name = xls.sheet_names[3]
df = pd.read_excel(file_path, sheet_name=sheet_name, engine='openpyxl')

# Display the contents of the fourth sheet in tabular format
print(df.to_string(index=False))