-1

I have a Bhav Copy Dataframe which is I Downloaded from NSE website. enter image description here

And In this Dataset I just wanna print Symbol Column.

print(bhav_copy['SYMBOL'])

but it is giving me this error, enter image description here

Sorry, I don't know what to say about this column name series in which only the Symbol column stored in a different format and other column stores in a different format in Bhav Copy Dataframe.

Artem Sokolov
  • 13,196
  • 4
  • 43
  • 74
Krishna Gupta
  • 166
  • 1
  • 10
  • I’m voting to close this question because it uses images of code and data – mozway Jan 12 '22 at 10:08
  • Please read [How to Ask](https://stackoverflow.com/help/how-to-ask), and [do not upload images of code/errors when asking a question.](https://meta.stackoverflow.com/questions/285551/why-not-upload-images-of-code-errors-when-asking-a-question) – Paul Jan 12 '22 at 10:09
  • 1
    Furthermore, I think you 'SYMBOL' column is actually your index. You could reset your index (`reset_index`) or print your index (`print(bhav_copy.index)`) – Paul Jan 12 '22 at 10:10
  • @Paul In my problem, there is no code, it's just a data frame which I can show through image, and next line I'm just print column which I have already written in code format. So how can I show this problem in code, please think practically? – Krishna Gupta Jan 12 '22 at 10:13
  • I guess you haven't read the info of the links I commented. – Paul Jan 12 '22 at 10:14
  • @paul you wrote, "I’m voting to close this question because it uses images of code and data ". Can you please tell me where I'm showing you picture of my code? I'm just showing you my data frame image because it is hard for me to explain my problem, I'm not good at English so I tried to show my problem by image. – Krishna Gupta Jan 12 '22 at 10:19
  • @Paul And If you think there is a better way of explain my problem, so why don't you just show me how to write it. – Krishna Gupta Jan 12 '22 at 10:23
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/240990/discussion-between-paul-and-krishna-gupta). – Paul Jan 12 '22 at 10:43

2 Answers2

1

KeyError exception happened when there is a mistake in column name

Check your SYMBOL column name if it spelled correctly and be carful column name is Case Sensitive, you can check columns names in Dataframe by using:

bhav_copy.columns

It should be formatted like that to print specific column data from a Dataframe:

bhav_copy[["SYMBOL"]]
bhav_copy["SYMBOL"]

The single bracket version gives a Pandas Series, the double bracket version gives a Pandas DataFrame.

For more info on this topic check this reference.

Oghli
  • 2,200
  • 1
  • 15
  • 37
0

reset_index technique worked for me.

bhav_copy.reset_index(inplace = True)
bhav_copy['SYMBOL']
Krishna Gupta
  • 166
  • 1
  • 10
  • Actually the problem not in resetting index, it's in your column name because it's case sensitive so when you write above `SYMBOL` name in capital case it gives you `KeyError` exception. – Oghli Jan 12 '22 at 11:29
  • @Oghli It was just my typing mistake brother. – Krishna Gupta Jan 12 '22 at 12:05
  • No problem be carful to the case of column name in the future. wish you the best. – Oghli Jan 12 '22 at 12:08