Python Forum
pandas dataframe substracting columns: key error
Thread Rating:
  • 2 Vote(s) - 3 Average
  • 1
  • 2
  • 3
  • 4
  • 5
pandas dataframe substracting columns: key error
#1
Hi Pandas Experts,

I got a dataframe that has a country and its GDP for the year 2015 up to 2006

    newfour = newtwo[(newtwo['2015']-newtwo['2006'])]
When I try to substract 2015 from 2006 and ingone the rest I read the error:

KeyError: '[  4.80566748e+12   1.75626949e+12   1.73021626e+11   2.46702696e+11\n   2.30356251e+11   2.28139911e+11   3.52665152e+11   1.10131180e+12\n   1.53345695e+11   3.25560528e+11  -1.52854060e+11   4.99867550e+09\n              nan   2.79311766e+11   4.74343726e+11] not in index'

It seems the GDP values are not an/in index but I wonder why that is required?
Why does a column need to be an index to be subtracted from another?
Many thanks for any explanations
Reply


Messages In This Thread
pandas dataframe substracting columns: key error - by metalray - Feb-23-2017, 12:56 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Pandas dataframe indexing pythonNovice 1 1,517 Jun-16-2022, 04:43 PM
Last Post: jefsummers
  How can I convert specific rows from excel to pandas dataframe? mcva 1 2,355 Apr-20-2020, 09:14 AM
Last Post: pyzyx3qwerty
  Histogram using pandas dataframe not showing proper output ift38375 1 3,323 Jul-04-2019, 10:43 PM
Last Post: scidam
  Need help getting unique values across two columns of a dataframe a_real_phoenix 1 2,441 Jun-30-2019, 01:46 AM
Last Post: scidam
  Pass 2 columns via loc to lambda in pandas fad3r 1 8,605 Feb-22-2018, 09:57 PM
Last Post: glidecode
  Substracting number with a limit mrplow92 3 3,829 Feb-01-2018, 06:04 PM
Last Post: gruntfutuk
  pandas dataframe next rows value metalray 2 11,019 Mar-06-2017, 11:31 AM
Last Post: metalray
  pandas dataframe group by count index metalray 5 11,739 Mar-01-2017, 09:14 AM
Last Post: metalray
  pandas dataframe.replace regex metalray 3 26,693 Feb-24-2017, 12:58 PM
Last Post: zivoni

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020