#!/usr/local/bin/python
# -*- coding: utf-8 -*-
import requests
import time
import csv
import datetime
import pandas as pd
import numpy as np


if __name__ == '__main__':
    name_file_base = 'indices_diesel_e_gasolina_base.csv'
    path_file_base = 'bases/'+name_file_base
    # começa a fazer os cálculos para o arquivo base
    df = pd.read_csv(path_file_base, sep=';')
    # converte os dados do dataframe
    df['data'] = pd.to_datetime(df['Data'], format='%d/%m/%Y', errors='ignore')
    del df['Data']

    count_nan = sum(pd.isnull(df['indice_gasolina']))
    while count_nan > 0:
        df['indice_gasolina'] = df['indice_gasolina'].fillna(value=(df['indice_gasolina'].shift(1) * df.Gasolina / 100) + df['indice_gasolina'].shift(1))
        df['indice_diesel'] = df['indice_gasolina'].fillna(value=(df['indice_diesel'].shift(1) * df.Diesel / 100) + df['indice_diesel'].shift(1))    
        count_nan -= 1

    df['indice_gasolina'] = df['indice_gasolina'].round(2)
    df['indice_diesel'] = df['indice_gasolina'].round(2)

    start_date = datetime.datetime(2017, 1, 1)
    all_days = pd.date_range(start_date, df['data'].max(), freq='D')
    df.index = pd.DatetimeIndex(df.data)
    df = df.reindex(all_days, fill_value=0)

    df[df['indice_gasolina'].eq(0)] = np.nan
    df[df['indice_diesel'].eq(0)] = np.nan

    count_nan = sum(pd.isnull(df['indice_gasolina']))
    while count_nan > 0:
        df['indice_gasolina'] = df['indice_gasolina'].fillna(value=(df['indice_gasolina'].shift(1)))
        df['indice_diesel'] = df['indice_gasolina'].fillna(value=(df['indice_diesel'].shift(1)))
        count_nan -= 1

    df['data'] = df.index
    del df['data']

    df['Gasolina'] = df['Gasolina'].fillna(value=0)
    df['Diesel'] = df['Diesel'].fillna(value=0)   

    df.index.name = 'data'

    print("Último registro do arquivo base", "\n", df.tail(1))

    # Salva o DataFrame em csv.
    saida_path_file_base = 'bases/saida_'+name_file_base
    df.to_csv(saida_path_file_base, sep=';', encoding='utf-8')
    print("Arquivo base csv salvo com sucesso:", "\n", saida_path_file_base)
    # Close the Pandas Excel writer and output the Excel file.
    saida_xlsx_file_base = 'bases/saida_xlsx_'+name_file_base+'.xlsx'
    writer = pd.ExcelWriter(saida_xlsx_file_base, engine='xlsxwriter')
    df.to_excel(writer, sheet_name='Sheet1')
    writer.save()
    print("Arquivo base csv salvo com sucesso", "\n", saida_xlsx_file_base)
b7eb140f0d18bc0cf6cf490bb70bf8470e2ee21e
<mask token>

<mask token>
if __name__ == '__main__':
    name_file_base = 'indices_diesel_e_gasolina_base.csv'
    path_file_base = 'bases/' + name_file_base
    df = pd.read_csv(path_file_base, sep=';')
    df['data'] = pd.to_datetime(df['Data'], format='%d/%m/%Y', errors='ignore')
    del df['Data']
    count_nan = sum(pd.isnull(df['indice_gasolina']))
    while count_nan > 0:
        df['indice_gasolina'] = df['indice_gasolina'].fillna(value=df[
            'indice_gasolina'].shift(1) * df.Gasolina / 100 + df[
            'indice_gasolina'].shift(1))
        df['indice_diesel'] = df['indice_gasolina'].fillna(value=df[
            'indice_diesel'].shift(1) * df.Diesel / 100 + df[
            'indice_diesel'].shift(1))
        count_nan -= 1
    df['indice_gasolina'] = df['indice_gasolina'].round(2)
    df['indice_diesel'] = df['indice_gasolina'].round(2)
    start_date = datetime.datetime(2017, 1, 1)
    all_days = pd.date_range(start_date, df['data'].max(), freq='D')
    df.index = pd.DatetimeIndex(df.data)
    df = df.reindex(all_days, fill_value=0)
    df[df['indice_gasolina'].eq(0)] = np.nan
    df[df['indice_diesel'].eq(0)] = np.nan
    count_nan = sum(pd.isnull(df['indice_gasolina']))
    while count_nan > 0:
        df['indice_gasolina'] = df['indice_gasolina'].fillna(value=df[
            'indice_gasolina'].shift(1))
        df['indice_diesel'] = df['indice_gasolina'].fillna(value=df[
            'indice_diesel'].shift(1))
        count_nan -= 1
    df['data'] = df.index
    del df['data']
    df['Gasolina'] = df['Gasolina'].fillna(value=0)
    df['Diesel'] = df['Diesel'].fillna(value=0)
    df.index.name = 'data'
    print('Último registro do arquivo base', '\n', df.tail(1))
    saida_path_file_base = 'bases/saida_' + name_file_base
    df.to_csv(saida_path_file_base, sep=';', encoding='utf-8')
    print('Arquivo base csv salvo com sucesso:', '\n', saida_path_file_base)
    saida_xlsx_file_base = 'bases/saida_xlsx_' + name_file_base + '.xlsx'
    writer = pd.ExcelWriter(saida_xlsx_file_base, engine='xlsxwriter')
    df.to_excel(writer, sheet_name='Sheet1')
    writer.save()
    print('Arquivo base csv salvo com sucesso', '\n', saida_xlsx_file_base)

import requests
import time
import csv
import datetime
import pandas as pd
import numpy as np
if __name__ == '__main__':
    name_file_base = 'indices_diesel_e_gasolina_base.csv'
    path_file_base = 'bases/' + name_file_base
    df = pd.read_csv(path_file_base, sep=';')
    df['data'] = pd.to_datetime(df['Data'], format='%d/%m/%Y', errors='ignore')
    del df['Data']
    count_nan = sum(pd.isnull(df['indice_gasolina']))
    while count_nan > 0:
        df['indice_gasolina'] = df['indice_gasolina'].fillna(value=df[
            'indice_gasolina'].shift(1) * df.Gasolina / 100 + df[
            'indice_gasolina'].shift(1))
        df['indice_diesel'] = df['indice_gasolina'].fillna(value=df[
            'indice_diesel'].shift(1) * df.Diesel / 100 + df[
            'indice_diesel'].shift(1))
        count_nan -= 1
    df['indice_gasolina'] = df['indice_gasolina'].round(2)
    df['indice_diesel'] = df['indice_gasolina'].round(2)
    start_date = datetime.datetime(2017, 1, 1)
    all_days = pd.date_range(start_date, df['data'].max(), freq='D')
    df.index = pd.DatetimeIndex(df.data)
    df = df.reindex(all_days, fill_value=0)
    df[df['indice_gasolina'].eq(0)] = np.nan
    df[df['indice_diesel'].eq(0)] = np.nan
    count_nan = sum(pd.isnull(df['indice_gasolina']))
    while count_nan > 0:
        df['indice_gasolina'] = df['indice_gasolina'].fillna(value=df[
            'indice_gasolina'].shift(1))
        df['indice_diesel'] = df['indice_gasolina'].fillna(value=df[
            'indice_diesel'].shift(1))
        count_nan -= 1
    df['data'] = df.index
    del df['data']
    df['Gasolina'] = df['Gasolina'].fillna(value=0)
    df['Diesel'] = df['Diesel'].fillna(value=0)
    df.index.name = 'data'
    print('Último registro do arquivo base', '\n', df.tail(1))
    saida_path_file_base = 'bases/saida_' + name_file_base
    df.to_csv(saida_path_file_base, sep=';', encoding='utf-8')
    print('Arquivo base csv salvo com sucesso:', '\n', saida_path_file_base)
    saida_xlsx_file_base = 'bases/saida_xlsx_' + name_file_base + '.xlsx'
    writer = pd.ExcelWriter(saida_xlsx_file_base, engine='xlsxwriter')
    df.to_excel(writer, sheet_name='Sheet1')
    writer.save()
    print('Arquivo base csv salvo com sucesso', '\n', saida_xlsx_file_base)

#!/usr/local/bin/python
# -*- coding: utf-8 -*-
import requests
import time
import csv
import datetime
import pandas as pd
import numpy as np


if __name__ == '__main__':
    name_file_base = 'indices_diesel_e_gasolina_base.csv'
    path_file_base = 'bases/'+name_file_base
    # começa a fazer os cálculos para o arquivo base
    df = pd.read_csv(path_file_base, sep=';')
    # converte os dados do dataframe
    df['data'] = pd.to_datetime(df['Data'], format='%d/%m/%Y', errors='ignore')
    del df['Data']

    count_nan = sum(pd.isnull(df['indice_gasolina']))
    while count_nan > 0:
        df['indice_gasolina'] = df['indice_gasolina'].fillna(value=(df['indice_gasolina'].shift(1) * df.Gasolina / 100) + df['indice_gasolina'].shift(1))
        df['indice_diesel'] = df['indice_gasolina'].fillna(value=(df['indice_diesel'].shift(1) * df.Diesel / 100) + df['indice_diesel'].shift(1))    
        count_nan -= 1

    df['indice_gasolina'] = df['indice_gasolina'].round(2)
    df['indice_diesel'] = df['indice_gasolina'].round(2)

    start_date = datetime.datetime(2017, 1, 1)
    all_days = pd.date_range(start_date, df['data'].max(), freq='D')
    df.index = pd.DatetimeIndex(df.data)
    df = df.reindex(all_days, fill_value=0)

    df[df['indice_gasolina'].eq(0)] = np.nan
    df[df['indice_diesel'].eq(0)] = np.nan

    count_nan = sum(pd.isnull(df['indice_gasolina']))
    while count_nan > 0:
        df['indice_gasolina'] = df['indice_gasolina'].fillna(value=(df['indice_gasolina'].shift(1)))
        df['indice_diesel'] = df['indice_gasolina'].fillna(value=(df['indice_diesel'].shift(1)))
        count_nan -= 1

    df['data'] = df.index
    del df['data']

    df['Gasolina'] = df['Gasolina'].fillna(value=0)
    df['Diesel'] = df['Diesel'].fillna(value=0)   

    df.index.name = 'data'

    print("Último registro do arquivo base", "\n", df.tail(1))

    # Salva o DataFrame em csv.
    saida_path_file_base = 'bases/saida_'+name_file_base
    df.to_csv(saida_path_file_base, sep=';', encoding='utf-8')
    print("Arquivo base csv salvo com sucesso:", "\n", saida_path_file_base)
    # Close the Pandas Excel writer and output the Excel file.
    saida_xlsx_file_base = 'bases/saida_xlsx_'+name_file_base+'.xlsx'
    writer = pd.ExcelWriter(saida_xlsx_file_base, engine='xlsxwriter')
    df.to_excel(writer, sheet_name='Sheet1')
    writer.save()
    print("Arquivo base csv salvo com sucesso", "\n", saida_xlsx_file_base)