pandas-datareader extract price value
up vote
0
down vote
favorite
I'm trying to get a list of the prices based in a DateTimeIndex, but since the column doesn't have a name how can I extract this value?
import pandas_datareader as pdr
start_date = datetime(2002,1,1).strftime("%Y-%m-%d")
end_date = datetime.now().strftime("%Y-%m-%d")
fx = pdr.get_data_fred("GOLDPMGBD228NLBM", start_date, end_date)
And I would like to retrieve a list from the values from the fx variable.
This is the current dataframe model:
In [41]: fx.head()
Out[41]:
GOLDPMGBD228NLBM
DATE
2002-01-01 NaN
2002-01-02 278.35
2002-01-03 278.80
2002-01-04 277.75
2002-01-07 278.60
I expect something like this:
x =
x = fx['Prices']
print(x)
['NaN', 278.35, 278.80, 277.75, 278.60]
Since I will work with many symbols I would like to handle it in a proper way.
python pandas
add a comment |
up vote
0
down vote
favorite
I'm trying to get a list of the prices based in a DateTimeIndex, but since the column doesn't have a name how can I extract this value?
import pandas_datareader as pdr
start_date = datetime(2002,1,1).strftime("%Y-%m-%d")
end_date = datetime.now().strftime("%Y-%m-%d")
fx = pdr.get_data_fred("GOLDPMGBD228NLBM", start_date, end_date)
And I would like to retrieve a list from the values from the fx variable.
This is the current dataframe model:
In [41]: fx.head()
Out[41]:
GOLDPMGBD228NLBM
DATE
2002-01-01 NaN
2002-01-02 278.35
2002-01-03 278.80
2002-01-04 277.75
2002-01-07 278.60
I expect something like this:
x =
x = fx['Prices']
print(x)
['NaN', 278.35, 278.80, 277.75, 278.60]
Since I will work with many symbols I would like to handle it in a proper way.
python pandas
1
Since that reader can return multiple prices depending on the codes you give it, it returns those codes as columns names... can you not either rename it or access it viafx['GOLDPMGBD228NLBM']
?
– Jon Clements♦
Nov 11 at 18:06
@JonClements I can do something like this a = [ x for x in fx['GOLDPMGBD228NLBM'] ]
– phxz
Nov 11 at 18:11
1
Well, if you want it as a list then usefx['GOLDPMGBD228NLBM'].tolist()
but then you lose all the advantages of having it as a DateTime index'dpandas.Series
object...
– Jon Clements♦
Nov 11 at 18:13
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I'm trying to get a list of the prices based in a DateTimeIndex, but since the column doesn't have a name how can I extract this value?
import pandas_datareader as pdr
start_date = datetime(2002,1,1).strftime("%Y-%m-%d")
end_date = datetime.now().strftime("%Y-%m-%d")
fx = pdr.get_data_fred("GOLDPMGBD228NLBM", start_date, end_date)
And I would like to retrieve a list from the values from the fx variable.
This is the current dataframe model:
In [41]: fx.head()
Out[41]:
GOLDPMGBD228NLBM
DATE
2002-01-01 NaN
2002-01-02 278.35
2002-01-03 278.80
2002-01-04 277.75
2002-01-07 278.60
I expect something like this:
x =
x = fx['Prices']
print(x)
['NaN', 278.35, 278.80, 277.75, 278.60]
Since I will work with many symbols I would like to handle it in a proper way.
python pandas
I'm trying to get a list of the prices based in a DateTimeIndex, but since the column doesn't have a name how can I extract this value?
import pandas_datareader as pdr
start_date = datetime(2002,1,1).strftime("%Y-%m-%d")
end_date = datetime.now().strftime("%Y-%m-%d")
fx = pdr.get_data_fred("GOLDPMGBD228NLBM", start_date, end_date)
And I would like to retrieve a list from the values from the fx variable.
This is the current dataframe model:
In [41]: fx.head()
Out[41]:
GOLDPMGBD228NLBM
DATE
2002-01-01 NaN
2002-01-02 278.35
2002-01-03 278.80
2002-01-04 277.75
2002-01-07 278.60
I expect something like this:
x =
x = fx['Prices']
print(x)
['NaN', 278.35, 278.80, 277.75, 278.60]
Since I will work with many symbols I would like to handle it in a proper way.
python pandas
python pandas
asked Nov 11 at 18:03
phxz
538
538
1
Since that reader can return multiple prices depending on the codes you give it, it returns those codes as columns names... can you not either rename it or access it viafx['GOLDPMGBD228NLBM']
?
– Jon Clements♦
Nov 11 at 18:06
@JonClements I can do something like this a = [ x for x in fx['GOLDPMGBD228NLBM'] ]
– phxz
Nov 11 at 18:11
1
Well, if you want it as a list then usefx['GOLDPMGBD228NLBM'].tolist()
but then you lose all the advantages of having it as a DateTime index'dpandas.Series
object...
– Jon Clements♦
Nov 11 at 18:13
add a comment |
1
Since that reader can return multiple prices depending on the codes you give it, it returns those codes as columns names... can you not either rename it or access it viafx['GOLDPMGBD228NLBM']
?
– Jon Clements♦
Nov 11 at 18:06
@JonClements I can do something like this a = [ x for x in fx['GOLDPMGBD228NLBM'] ]
– phxz
Nov 11 at 18:11
1
Well, if you want it as a list then usefx['GOLDPMGBD228NLBM'].tolist()
but then you lose all the advantages of having it as a DateTime index'dpandas.Series
object...
– Jon Clements♦
Nov 11 at 18:13
1
1
Since that reader can return multiple prices depending on the codes you give it, it returns those codes as columns names... can you not either rename it or access it via
fx['GOLDPMGBD228NLBM']
?– Jon Clements♦
Nov 11 at 18:06
Since that reader can return multiple prices depending on the codes you give it, it returns those codes as columns names... can you not either rename it or access it via
fx['GOLDPMGBD228NLBM']
?– Jon Clements♦
Nov 11 at 18:06
@JonClements I can do something like this a = [ x for x in fx['GOLDPMGBD228NLBM'] ]
– phxz
Nov 11 at 18:11
@JonClements I can do something like this a = [ x for x in fx['GOLDPMGBD228NLBM'] ]
– phxz
Nov 11 at 18:11
1
1
Well, if you want it as a list then use
fx['GOLDPMGBD228NLBM'].tolist()
but then you lose all the advantages of having it as a DateTime index'd pandas.Series
object...– Jon Clements♦
Nov 11 at 18:13
Well, if you want it as a list then use
fx['GOLDPMGBD228NLBM'].tolist()
but then you lose all the advantages of having it as a DateTime index'd pandas.Series
object...– Jon Clements♦
Nov 11 at 18:13
add a comment |
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53251636%2fpandas-datareader-extract-price-value%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
1
Since that reader can return multiple prices depending on the codes you give it, it returns those codes as columns names... can you not either rename it or access it via
fx['GOLDPMGBD228NLBM']
?– Jon Clements♦
Nov 11 at 18:06
@JonClements I can do something like this a = [ x for x in fx['GOLDPMGBD228NLBM'] ]
– phxz
Nov 11 at 18:11
1
Well, if you want it as a list then use
fx['GOLDPMGBD228NLBM'].tolist()
but then you lose all the advantages of having it as a DateTime index'dpandas.Series
object...– Jon Clements♦
Nov 11 at 18:13