What is the error in the Python chart

Asked

Viewed 59 times

1

When I put print on file 2 it displays me the data from the first'file'

import urllib.request
import pandas as pd
import datetime
import matplotlib.pyplot as plt

origem = 'http://api.bcb.gov.br/dados/serie/bcdata.sgs.10813/dados?formato=csv'
arquivo = 'dolar_bcb_api.csv'
origem2 = 'http://api.bcb.gov.br/dados/serie/bcdata.sgs.10822/dados?formato=csv'
arquivo2 = 'divida_publica_externa.csv'

urllib.request.urlretrieve(origem, arquivo)
urllib.request.urlretrieve(origem2, arquivo2)

dateparse = lambda x: pd.datetime.strptime(x, '%d/%m/%Y')
df_dolar = pd.read_csv(arquivo, encoding = "utf-8", delimiter=';', index_col=0,
                       parse_dates=['data'],
                       date_parser=dateparse)

df_divida = pd.read_csv(arquivo2, encoding = "utf-8", delimiter=';', index_col=0,
                       parse_dates=['data'],
                       date_parser=dateparse)

df_dolar.index.names = ['Data']
df_dolar.columns = ['Dolar']
df_dolar['Dolar'] = df_dolar['Dolar'].str.replace(',', '.').astype(float)

df_divida.index.names = ['Data']
df_divida.columns = ['Dolar']
df_divida['Dolar'] = df_divida['Dolar'].str.replace(',', '.').astype(float)

data_inicial = datetime.datetime.strptime('2006' + \
       "-" + '01' + "-" + '01', "%Y-%m-%d")

data_final = datetime.datetime.strptime('2020' + \
       "-" + '12' + "-" + '31', "%Y-%m-%d")

df_dolar = df_dolar.loc[data_inicial:data_final]
df_divida = df_dolar.loc[data_inicial:data_final]


print(df_divida)

1 answer

0


I think that might be your problem

...

df_dolar = df_dolar.loc[data_inicial:data_final]
#df_divida = df_dolar.loc[data_inicial:data_final]
#             ^
#            Voce esta utilizando `df_dolar` acho que você queria o `df_divida`
df_divida = df_divida.loc[data_inicial:data_final]

print(df_divida)
  • 1

    Puts brother was that same valewzao tmjj

Browser other questions tagged

You are not signed in. Login or sign up in order to post.