Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to edit a csv file using urllib?
    primarykey
    data
    text
    <p>I want to download and manipulate a csv file when I open a historical stock quotes from Yahoo finance.</p> <p>A brief glimpse of how the csv file looks like:</p> <pre><code>Date,Open,High,Low,Close,Volume,Adj Close 2012-11-30,691.31,699.22,685.69,698.37,3163600,698.37 2012-11-29,687.78,693.90,682.00,691.89,2776500,691.89 2012-11-28,668.01,684.91,663.89,683.67,3042000,683.67 </code></pre> <p>I want to create a code that erases the word "open, High, Low, Close, Volume, Adj" and the data underneath it, and also add two new columns, giving me:</p> <pre><code>Date Close [Insert new column here] [Another column] 2012-11-30 698.37 ---some data---- ---some data---- 2012-11-29 691.89 ---some data---- ---some data---- 2012-11-28 683.67 ---some data---- ---some data---- </code></pre> <p>I am a beginner in using Python, so I am having a bit of trouble writing this code. If someone can help me out, I'd appreciate it very much.</p> <p>So far, this is what I have, though it doesn't clearly work the way I want it to.</p> <pre><code>def _download_url(url): response = None try: response = urllib.request.urlopen(url) content_bytes=response.read() content_string=content_bytes.decode(encoding='utf-8') data = io.StringIO(content_string) mycsv=csv.reader(data) for row in mycsv: if row: print(row[0],row[6]) </code></pre> <p>This code prints out (a brief glimpse):</p> <pre><code>Date Adj Close 2012-11-30 698.37 2012-11-29 691.89 2012-11-28 683.67 2012-11-27 670.71 </code></pre> <p>It's kind of what I want, but I want to erase "Adj" and also add two new columns. thank you!</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload