Home > database >  Pandas TypeError: unsupported operand type(s) for -: 'float' and 'str' (Python)
Pandas TypeError: unsupported operand type(s) for -: 'float' and 'str' (Python)

Time:10-19

Combining Series into DataFrames Using the aud_usd_lst and eur_aud_lst lists defined in the scaffold on the right, perform the following tasks:

  1. Create a series named aud_usd_series with non-missing quotes for the AUD/USD exchange rate. Specifically:

The series should have dates as row labels. There should be no missing AUD/USD values.

  1. Create a series named eur_aud_series with non-missing quotes for the EUR/AUD exchange rate. Specifically:

The series should have dates as row labels. There should be no missing EUR/AUD values.

  1. Combine the two series into a data frame named df, so it has the dates as row labels and 'AUD/USD', 'EUR/AUD' as column labels.
import pandas as pd
import numpy as np
from unanswered import *

aud_usd_lst = [
    ('2020-09-08', 0.7280),
    ('2020-09-09', 0.7209),
    ('2020-09-11', 0.7263),
    ('2020-09-14', 0.7281),
    ('2020-09-15', 0.7285),
    ]

eur_aud_lst = [
    ('2020-09-08',  1.6232),
    ('2020-09-09',  1.6321),
    ('2020-09-10',  1.6221),
    ('2020-09-11',  1.6282),
    ('2020-09-15',  1.6288),
    ]

Here is my Code:

aud_usd_series = pd.Series(np.array(aud_usd_lst)[:,1], index=np.array(aud_usd_lst)[:,0])
aud_usd_series

eur_aud_series = eur_aud_series = pd.Series(np.array(eur_aud_lst)[:,1], index=np.array(eur_aud_lst)[:,0])
eur_aud_series

df = pd.DataFrame([aud_usd_series,eur_aud_series]).T
df.columns = ['AUD/USD','EUR/AUD']
df

I tried to run the code and it says

TypeError: unsupported operand type(s) for -: 'float' and 'str'

ANY Suggestion?

CodePudding user response:

TypeError: unsupported operand type(s) for -: 'float' and 'str'

This means you make operation between float and string that not possible

  • Related