Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
multiple problems with code
#1
values = melb_data[melb_data.Suburb == "Brighton East"].CouncilArea.mode()[0]
print("V",values)
melb_data[melb_data.Suburb == "Brighton East"].CouncilArea.fillna(value = values,inplace = True)not

the fillna function is not working can anybody help me pls
Reply
#2
please read: https://python-forum.io/misc.php?action=help&hid=19
Reply
#3
for i in Suburb:
values = melb_data[melb_data.Suburb == i].CouncilArea.mode()[0]
mask = melb_data[melb_data.Suburb == i]['CouncilArea'].isnull()
melb_data[melb_data.Suburb == i].CouncilArea.fillna(value = values,inplace = True)
and the error is
---------------------------------------------------------------------------
KeyError Traceback (most recent call last)
~\Anaconda3\lib\site-packages\pandas\core\indexes\base.py in get_value(self, series, key)
4374 return self._engine.get_value(s, k,
-> 4375 tz=getattr(series.dtype, 'tz', None))
4376 except KeyError as e1:

pandas/_libs/index.pyx in pandas._libs.index.IndexEngine.get_value()

pandas/_libs/index.pyx in pandas._libs.index.IndexEngine.get_value()

pandas/_libs/index.pyx in pandas._libs.index.IndexEngine.get_loc()

pandas/_libs/hashtable_class_helper.pxi in pandas._libs.hashtable.Int64HashTable.get_item()

pandas/_libs/hashtable_class_helper.pxi in pandas._libs.hashtable.Int64HashTable.get_item()

KeyError: 0

During handling of the above exception, another exception occurred:

IndexError Traceback (most recent call last)
<ipython-input-25-ad558584b420> in <module>
1 for i in Suburb:
----> 2 values = melb_data[melb_data.Suburb == i].CouncilArea.mode()[0]
3 mask = melb_data[melb_data.Suburb == i]['CouncilArea'].isnull()
4 melb_data[melb_data.Suburb == i].CouncilArea.fillna(value = values,inplace = True)

~\Anaconda3\lib\site-packages\pandas\core\series.py in __getitem__(self, key)
866 key = com.apply_if_callable(key, self)
867 try:
--> 868 result = self.index.get_value(self, key)
869
870 if not is_scalar(result):

~\Anaconda3\lib\site-packages\pandas\core\indexes\base.py in get_value(self, series, key)
4379
4380 try:
-> 4381 return libindex.get_value_box(s, key)
4382 except IndexError:
4383 raise

pandas/_libs/index.pyx in pandas._libs.index.get_value_box()

pandas/_libs/index.pyx in pandas._libs.index.get_value_at()

pandas/_libs/util.pxd in pandas._libs.util.get_value_at()

pandas/_libs/util.pxd in pandas._libs.util.validate_indexer()

IndexError: index out of bounds
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  code problems bbm007 5 1,091 Apr-20-2023, 08:36 PM
Last Post: deanhystad
  python multiple try except block in my code -- can we shorten code mg24 10 5,893 Nov-10-2022, 12:48 PM
Last Post: DeaD_EyE
  Encoding problems on multiple files in one folder NikolajKorsgaard 5 3,944 Jun-11-2019, 03:39 AM
Last Post: micseydel
  code problems lokchi2017 3 2,665 Jul-06-2018, 01:58 AM
Last Post: Zombie_Programming
  code editor/ IDE problems nameno1had 2 3,280 Mar-12-2018, 10:09 PM
Last Post: snippsat
  Running a code through multiple files in a folder Rai 1 2,461 Feb-13-2018, 12:42 PM
Last Post: Larz60+
  Multiple Question Results code flynnmackie 2 65,312 Mar-13-2017, 06:54 PM
Last Post: snippsat

Forum Jump:

User Panel Messages

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