我有一个本地git repo,我正试图找到一种方法,将特定版本的xlsx文件放入python代码中,以便使用pandas处理它
我找到了gitpython库,但我不确定如何正确使用它
repo = Repo(path_to_repo)
commit = repo.commit(sha)
targetfile = commit.tree / 'dataset.xlsx'
但我不知道下一步该怎么办
如何将以前版本的xlsx加载到pandas?
我有一个本地git repo,我正试图找到一种方法,将特定版本的xlsx文件放入python代码中,以便使用pandas处理它
我找到了gitpython库,但我不确定如何正确使用它
repo = Repo(path_to_repo)
commit = repo.commit(sha)
targetfile = commit.tree / 'dataset.xlsx'
但我不知道下一步该怎么办
如何将以前版本的xlsx加载到pandas?
当你要commit.tree / 'dataset.xlsx'
块时,你会得到一个git.Blob
块的东西:
>>> targetfile
<git.Blob "3137d9443f54325b8ad8a263b13053fee47fbff2">
如果要读取对象的内容,可以使用data_stream
方法提取内容,该方法返回类似文件的对象:
>>> data = targetfile.data_stream.read()
或者你可以使用stream_data
方法(不要看我,我没有说出他们的名字),它将数据写入一个类似文件的对象:
>>> import io
>>> buf = io.BytesIO()
>>> targetfile.stream_data(buf)
<git.Blob "3137d9443f54325b8ad8a263b13053fee47fbff2">
>>> buf.getvalue()
b'The contents of the file...'