Convert text data from requests object to dataframe with pandas
<p>Using requests I am creating an object which is in .csv format. How can I then write that object to a DataFrame with pandas?</p>

<p>To get the requests object in text format:</p>

<pre><code>import requests
import pandas as pd
url = r'http://test.url' 
r = requests.get(url)
r.text  #this will return the data as text in csv format
</code></pre>

<p>I tried (doesn't work):</p>

<pre><code>pd.read_csv(r.text)
pd.DataFrame.from_csv(r.text)
</code></pre>

<p>I think you can use <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.read_csv.html" rel="nofollow"><code>read_csv</code></a> with <code>url</code>:</p>

<pre><code>pd.read_csv(url)
</code></pre>

<blockquote>
  <p><strong>filepath_or_buffer</strong> : str, pathlib.Path, py._path.local.LocalPath or any object with a read() method (such as a file handle or StringIO)</p>
  
  <p>The string could be a URL. Valid URL schemes include http, ftp, s3, and file. For file URLs, a host is expected. For instance, a local file could be file ://localhost/path/to/table.csv</p>
</blockquote>

<p>If it doesnt work, try:</p>

<pre><code>import pandas as pd
import io
import requests

url = r'http://...' 
r = requests.get(url)  
df = pd.read_csv(io.StringIO(r) 
</code></pre>

python csv pandas dataframe python-requests