In competitions, etc., the file reading process and import module will change between local and cloud, so it will be possible to switch automatically. Kaggle, Google Colaboratory, Local (Windows 10)
Discrimination method,
Please let me know if there is a smarter judgment method.
import os
# windows
if os.name == 'nt':
path = '../input/data/'
import japanize_matplotlib
sns.set(font="IPAexGothic")
elif os.name == 'posix':
# Kaggle
if 'KAGGLE_DATA_PROXY_TOKEN' in os.environ.keys():
path = '/kaggle/input/'
# Google Colab
else:
from google.colab import drive
drive.mount('/content/drive')
!ls drive/My\ Drive/'Colab Notebooks'/xxx #xxx rewrite
path = "./drive/My Drive/Colab Notebooks/xxx/input/data/" #xxx rewrite
#Check the remaining time of the session
!cat /proc/uptime | awk '{print $1 /60 /60 /24 "days (" $1 / 60 / 60 "h)"}'
print(os.name)
print(path)
Recommended Posts