Axblert
Axblert

Reputation: 576

Currency Conversion Dataframe - skip Columns

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?

Upvotes: 0

Views: 60

Answers (1)

Mykola Zotko
Mykola Zotko

Reputation: 17882

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

Upvotes: 1

Related Questions