data for example
10/11/2015,129.177551
how do I build two lists?
Date [] and price [] should contain date and price separately
>Solution :
If you data is in csv, you can use pandas package:
file.csv
10/11/2015,129.177551
10/11/2015,129.177551
import pandas
df = pandas.read_csv('file.csv', header=False)
date = df.iloc[0,:].tolist()
price = df.iloc[1,:].tolist()
Though most people just leave the data in the pandas DataFrame for further processing.
If you data is in a string
data = '''10/11/2015,129.177551
10/11/2015,129.177551'''
data = [line.split(',') for line in data.split('\n')]
date, price = zip(*data)
And if you want to use for loop:
data = '''10/11/2015,129.177551
10/11/2015,129.177551'''
date = []
price = []
for line in data.split('\n'):
d, p = line.split(',')
date.append(d)
price.append(p)
As you can see, method 1 (list comprehension) is much shorter.