我想将csv文件加载到pandas数据框架中,并且该数据在远程服务器上可用。
目标是直接将其读入数据帧,而不将数据写入磁盘。
url = https://dev.azure.com/tankerkoenig/tankerkoenig-data/_git/tankerkoenig-data?path=/prices/2022/07/2022-07-01-prices.csv
我正在考虑这样一个方法:
import requests
import pandas as pd
r = requests.get(url)
df = pd.read_csv(r.content)
有人知道这样的事情是可能的吗?
可以直接调用read_csv
方法
import pandas as pd
url="https://dev.azure.com/tankerkoenig/tankerkoenig-data/_git/tankerkoenig-data?path=/prices/2022/07/2022-07-01-prices.csv"
df=pd.read_csv(url)
OR如果你想要字符串形式的文本并读取
from io import StringIO
import pandas as pd
import requests
url='https://dev.azure.com/tankerkoenig/tankerkoenig-data/_git/tankerkoenig-data?path=/prices/2022/07/2022-07-01-prices.csv'
s=requests.get(url).text
df=pd.read_csv(StringIO(s))