如何从github将.txt文件读入Google Colab [英] How to read .txt files from github into Google colab
本文介绍了如何从github将.txt文件读入Google Colab的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在github中有一个包含文本文件的文件夹,当我尝试在Google colab中阅读以下代码时,出现错误
I have folder in github which contains text files and when I tried to read below code in Google colab I'm getting error
FileNotFoundError:[错误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:
You can download all files in that directory to Colab first with:
!npx degit Jainu-s/urldata/al -f
然后,您可以像本地文件一样将其循环.
Then, you can loop it like local files.
这篇关于如何从github将.txt文件读入Google Colab的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文