Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I am retrieving Yahoo stock ticker data and want to convert the given currency to euros. For this purpose I am using the Python Library Currency Converter and the pandas method multiply.

One of the columns, trading volume, shouldn't be "converted" - whats the best way to skip it? This is what I currently have:

import pandas as pd
import datetime
import pandas_datareader.data as web
from pandas import Series, DataFrame
from currency_converter import CurrencyConverter

start = datetime.datetime(2017, 1, 1)
end = datetime.datetime(2020, 12, 31)


c = CurrencyConverter()

df = web.DataReader("EXK", 'yahoo', start, end)
df.tail()

conversion = c.convert(1, 'USD', 'EUR')

eurodf = df.multiply(conversion,axis='rows')
eurodf.tail()

One approach I thought of taking, was to maybe join the "volume" column after multiplication. Alternatively I could just target that one column and convert it back?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
3.8k views
Welcome To Ask or Share your Answers For Others

1 Answer

You can loc all columns except one. For example:

   A  B  C
0  0  1  2
1  3  4  5
2  6  7  8

df.loc[:, df.columns.drop('B')] *= 10

Result:

    A  B   C
0   0  1  20
1  30  4  50
2  60  7  80

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share

548k questions

547k answers

4 comments

86.3k users

...