# ---
# jupyter:
#   jupytext:
#     text_representation:
#       extension: .py
#       format_name: light
#       format_version: '1.5'
#       jupytext_version: 1.14.4
#   kernelspec:
#     display_name: Python 3
#     name: python3
# ---

# + id="7vBWogMMyEyu" colab_type="code" colab={}
import pandas as pd

ARQUIVO_OCEANS = 'dados_oceans14_final.csv'
ARQUIVO_STATUS = 'dados_status_invest-2020_06_15.csv'
df_oceans = pd.read_csv('Oceans14/'+ARQUIVO_OCEANS, encoding='utf-8')
df_status = pd.read_csv('Status Invest/'+ARQUIVO_STATUS, encoding='utf-8')

# + id="qiAZw1n6bAeQ" colab_type="code" colab={}
df_status['ano'] = 2020

# + [markdown] id="fefYF2cHM_Z_" colab_type="text"
# Listando as colunas exclusivas de cada base de dados

# + id="Y-nxbwGW3RUr" colab_type="code" colab={}
colunas_exclusivas_oceans = list(set(df_oceans.columns) - set(df_status.columns))

# + id="reTwzlxP3Xpy" colab_type="code" colab={}
colunas_exclusivas_status = list(set(df_status.columns) - set(df_oceans.columns))

# + [markdown] id="P4nWE5KtNEWQ" colab_type="text"
# Separando da Status os dados das empresas que tem na Oceans14

# + id="9b-P-C7AT54O" colab_type="code" colab={}
ticks_oceans = list(df_oceans['tick'].unique())

# + id="Jb_Oepa7VZyd" colab_type="code" colab={}
df_status = df_status[df_status['tick'].isin(ticks_oceans)].copy()

# + id="s2bnnVyHbMml" colab_type="code" colab={}
df_oceans = df_oceans.set_index('tick')
df_status = df_status.set_index('tick')

# + [markdown] id="tBh10FoeNOVV" colab_type="text"
# ## Separando apenas os dados de 2020 da Oceans14

# + id="OGmmiKLj9Vuv" colab_type="code" colab={}
df_oceans_2020 = df_oceans[df_oceans['ano'] == 2020]

# + id="DFzVK4A5Ilbr" colab_type="code" colab={"base_uri": "https://localhost:8080/", "height": 883} outputId="5e6e7ae4-2d3e-4857-d6ad-11524eb5a390"
df_oceans_2020[colunas_exclusivas_oceans]

# + [markdown] id="DVOSNWqXNVut" colab_type="text"
# Concatenando dados Status com da Oceans14

# + id="pJo7s8b3HQWo" colab_type="code" colab={}
#pd.concat([df_oceans_2020[colunas_exclusivas_oceans], df_status], axis=1)
df_2020_final = df_status.join(df_oceans_2020[colunas_exclusivas_oceans])

# + id="tB9Dsx1jMBqJ" colab_type="code" colab={"base_uri": "https://localhost:8080/", "height": 903} outputId="a3d5d31e-edba-41d0-da0b-900cef642473"
df_2020_final.fillna(0, inplace=True)
df_2020_final

# + id="NTTMY18hI-rY" colab_type="code" colab={}
df_2020_final.to_csv('dados_2020_final.csv', encoding='utf-8')

# + [markdown] id="y2I8jwOa9c0Y" colab_type="text"
# ## Juntando as duas bases, mesmo que em anos anteriores, varias colunas estejam faltando

# + [markdown] id="_Cd5cqoqG9Uy" colab_type="text"
# Filtra os dados da Oceans14 em ano = 2020, e junta com dados da Status, que só tem 2020

# + id="6IBlFjIn9lZQ" colab_type="code" colab={}
df_oceans_status_2020 = df_oceans[df_oceans['ano'] == 2020][colunas_exclusivas_oceans].join(df_status).copy()

# + [markdown] id="HCMlflVjHIhz" colab_type="text"
# Junta os dados completos de 2020 com os outros da Oceans14.
# Isso gera varios NaN, esperado.

# + id="-R8S1xi8_Ike" colab_type="code" colab={}
df_oceans_status = pd.concat([df_oceans[df_oceans['ano'] != 2020], df_oceans_status_2020])

# + id="jXZpMXqcG2wm" colab_type="code" colab={}
df_oceans_status.to_csv('dados_oceans_status.csv', encoding='utf-8')

StarcoderdataJupyterScriptsDedupFiltered