Repository navigation
Description
해결하고자 하는 문제
코랩에서 파일을 불러올 때 csv, xlsx는 되는데
구글 스프레드시트(확장자 gsheet) 파일을 불러오는 방법을 모르겠습니다.
코드 혹은 오류
StopIteration Traceback (most recent call last)
/usr/local/lib/python3.7/dist-packages/gspread/client.py in open(self, title)
121 lambda x: x['name'] == title,
--> 122 self.list_spreadsheet_files()
123 )
2 frames
StopIteration:
During handling of the above exception, another exception occurred:
SpreadsheetNotFound Traceback (most recent call last)
/usr/local/lib/python3.7/dist-packages/gspread/client.py in open(self, title)
128 return Spreadsheet(self, properties)
129 except StopIteration:
--> 130 raise SpreadsheetNotFound
131
132 def open_by_key(self, key):
SpreadsheetNotFound:
환경
윈도우 10 노트북에서 크롬 브라우저를 통해 코랩에 접속해서 작업
시도해본 방법
검색을 해보니 아래 링크와 같은 내용이 있어서 그대로 따라 했습니다.(더 마땅한 내용을 못찾았습니다.)
https://colab.research.google.com/notebooks/io.ipynb#scrollTo=sOm9PFrT8mGG
위 링크의 내용을 따라 하면서 새 시트명까지 "My cool spreadsheet"로 만들고
제가 엑셀에 가지고 있던 데이터를 붙여넣기 하고,
링크에 있는 것 처럼 "My cool spreadsheet"파일을 불러오면 정상적으로 불러옵니다.
그런데,
worksheet = gc.open('My cool spreadsheet').sheet1 에서 파일명 대신
1번: /content/drive/MyDrive/Colab Notebooks/mydata/hantaro_60x14.gsheet
2번: https://drive.google.com/drive/folders/1Ob3VDeCWTDrd45pOG2nXfnd51vvNIXR6/hantaro_60x14.gsheet
두 가지 경로를 입력하면 오류메시지(1번에 대한 오류)가 뜸니다.
권한 인증 등의 문제는 없는 것 같은데, 제 구글 드라이브 하위 폴더에 있는 스프레드시트 파일을
불러올 수 있는 방법 알려주시면 감사하겠습니다.
Activity
RayleighKim commentedon Jul 28, 2021
혹시 이 스택 오버플로우의 예시를 활용해보시면 어떨까요?
물론 이 방법은, 구글 스프레드 시트가 링크가 있는 모든 사용자에게 보기 권한이 있는 경우 동작합니다.
progh2 commentedon Jul 30, 2021
위처럼 해보시기 동작하네요.
사용자 인증 하고 gdrive 연결한 후에 했습니다.
경로가 /content/drive/MyDrive/ 바로 아래서 시작해서위처럼만 해도 불러와집니다.
이녀석은 왜 저 경로부터 시작인지 신기하네요.
이전 질문 덕에 저도 좋은 것을 알게 되었네요. 구글스프레드시트 데이터 가공이 필요할 때
코랩으로 하기 딱 좋겠습니다. 🍕