0

I´m spending a lot of time trying to set my panel data.

Everytime that I run the following command df.set_index(['id', 'datas'] I have the message that "None of ['id', 'datas'] are in the columns", as show below, but they are.

What´s happening? Someone can help me?

---------------------------------------------------------------------------
KeyError                                  Traceback (most recent call last)
<ipython-input-4-219574cda450> in <module>
      1 # Configurando o painel
----> 2 df.set_index(['id', 'datas'], inplace=True)
      3 
      4 # Realizando a regressão POLS
      5 X_pols = df[['perc_qtd_neg_lei', 'ampl_log_0', 'distperc_vwap_inicio_lei', 'segunda', 'terca', 'quarta', 'sexta']]

~\anaconda3\lib\site-packages\pandas\core\frame.py in set_index(self, keys, drop, append, inplace, verify_integrity)
   4549 
   4550         if missing:
-> 4551             raise KeyError(f"None of {missing} are in the columns")
   4552 
   4553         if inplace:

KeyError: "None of ['id', 'datas'] are in the columns"
2
  • It looks like you're encountering a KeyError when trying to set the index of your DataFrame using the df.set_index(['id', 'datas'], inplace=True) command. It looks like you're encountering a KeyError when trying to set the index of your DataFrame using the df.set_index(['id', 'datas'], inplace=True) command. Double-check that the column names 'id' and 'datas' are spelled correctly and exactly match the names in your DataFrame. Commented Sep 2, 2023 at 1:48
  • What is the output of print(df.columns)? Commented Sep 2, 2023 at 1:52

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.