I have data in this format:
2017-08-01,5.6
2017-09-01,5.6
2017-10-01,5.6
2017-11-01,5.5
2017-12-01,5.5
2018-01-01,5.4
2018-02-01,5.4
This data variable was created in this way:
data= fred.get_series('LMUNRRTTDEM156S').to_csv()
I have successfully inserted the data into separate columns and rows in a csv file but how could i filter the data variable to say: "only write the rows with a date later than 2010-01-01"? Also how can i define column names, i tried a simple write f.write('col1', 'col2') but this failed?
with open("fileName.csv", "w") as f:
f.write(data)
f.close()
Full code:
from fredapi import Fred
import csv
import pandas as pd
fred= Fred(api_key= 'XYZ')
data= fred.get_series('LMUNRRTTDEM156S').to_csv()
with open("fileName.csv", "w") as f:
#f.write('hello', 'world')
f.write(data)
f.close()
Any help would be greatly appreciated
datais a string so, can you share how you built it ? edit your post and add more codeget_seriesdata returns a Pandas Series object