[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

I try to edit and find data from a text file with python 2.7 (data from stock market)


I try to edit a text file with python 2.7:

***** AAPL *****
Date: September 07 2018
Time: 14:10:52
Price: ,068,407
Ask: None
High: None
Low: None
Previous Close: ,068,407
Volume: $?227.35?/?$?221.30
Market Cap: 20.23

but when I write it to a file I get:
{'previous_close': ',068,407', 'volume': u'$\xa0227.35\xa0/\xa0$\xa0221.30', 'market_cap': '20.23', 'price': ',068,407', 'high': 'None', 'ask': 'None', 'low': 'None', 'time': '14:15:45', 'date': 'September 07 2018', 'ticker': 'AAPL'}

why is that? and how do I get the price value only? so I will have only that in a variable? for example the variable: Price.

this is my code..
import csv
import itertools
from nasdaq_stock import nasdaq_stock


with open("log.txt", "w") as text_file:

with open('log.txt', 'r') as in_file:
    lines = in_file.read().splitlines()
    stripped = [line.replace(","," ").split() for line in lines]
    grouped = itertools.izip(*[stripped]*1)
    with open('log.csv', 'w') as out_file:
        writer = csv.writer(out_file)
        writer.writerow(('title', 'intro', 'tagline'))
        for group in grouped:

#locate cell
import csv

def read_cell(x, y):
    with open('log.csv', 'r') as f:
        reader = csv.reader(f)
        y_count = 0
        for n in reader:
            if y_count == y:
                cell = n[x]
                return cell
            y_count += 1
#I try to find the value of Price..
print (read_cell(2,3))