简体   繁体   English

将 .iqy 文件中的数据导入 Pandas

[英]Importing data in .iqy files into Pandas

I have several .iqy files that query data from Sharepoint.我有几个从 Sharepoint 查询数据的 .iqy 文件。 I need to combine and process these in Python Pandas.我需要在 Python Pandas 中组合和处理这些。 Does Python have any way of doing this? Python 有没有办法做到这一点? I know the Python Sharepoint library exists, but I'm trying to avoid setting up my own connections via Python and rely on the .iqy files instead.我知道 Python Sharepoint 库存在,但我试图避免通过 Python 设置我自己的连接,而是依赖 .iqy 文件。 Any ideas?有什么想法吗?

For sake of the question, assume the table looks like this:为了这个问题,假设表格如下所示:

+------+------+
| col1 | col2 |
+------+------+
|    1 |    2 |
|    3 |    4 |
+------+------+

Also I'm open to non-Python solutions for a way to automatically run the .iqy queries and get the data into a Python-readable format (eg .csv).此外,我对非 Python 解决方案持开放态度,以寻求一种自动运行 .iqy 查询并将数据转换为 Python 可读格式(例如 .csv)的方法。 Not sure what such an approach looks like though虽然不确定这种方法是什么样的

Here is a little hacky-way:这是一个小技巧:

import requests_ntlm
import requests

url = 'https://..../owssvr.dll?XMLDATA=...'
print('downloading...')
r = requests.get(url, auth=requests_ntlm.HttpNtlmAuth(LOGIN, PASSWORD), verify=False)

print('saving...')
with open('download.xml', 'wb') as file:
    file.write(r.content)

A few remarks:几点说明:

  1. url is in *.iqy file (typically is very long). url在 *.iqy 文件中(通常很长)。 You can extract it manually by "notepad" or parse it by python.您可以通过“记事本”手动提取它或通过python解析它。
  2. You'll get xml file, to convert it to pandas dataframe look at: How to convert an XML file to nice pandas dataframe?您将获得 xml 文件,将其转换为熊猫数据帧,请查看: 如何将 XML 文件转换为漂亮的熊猫数据帧?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM