如何将 .txt 文件从 github 读入 Google colab

耆那教

我在 github 中有包含文本文件的文件夹,当我尝试在 Google colab 中阅读以下代码时出现错误

FileNotFoundError: [Errno 2] 没有这样的文件或目录:' https://github.com/Jainu-s/urldata/tree/master/al?raw=true '

loc = 'https://github.com/Jainu-s/urldata/tree/master/al?raw=true'
#uploaded = files.upload()
os.chdir(loc)
filelist = os.listdir()
#print (len((pd.concat([pd.read_csv(item, names=[item[:-4]]) for item in filelist],axis=1))))

data = []
path = loc
files = [f for f in os.listdir(path) if os.path.isfile(f)]
for f in files:
    with open(f,'r') as myfile:
        data.append(myfile.read())


df = pd.DataFrame(data,columns=['Data'])
print (df.shape)
科拉科特

您可以首先使用以下命令将该目录中的所有文件下载到 Colab:

!npx degit Jainu-s/urldata/al -f

然后,您可以像本地文件一样循环它。

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章