Python Forum
Fix pandas copy/slice warning.
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Fix pandas copy/slice warning.
#2
Probably this won't help you, I don't know pandas. I was just looking at your code, trying to learn a bit about pandas.

If I assign:

description = supplier_table["Description"] 
type(description)
<class 'pandas.core.series.Series'>
Try split() on description:

description.split()
Traceback (most recent call last):
  File "/usr/lib/python3.10/idlelib/run.py", line 578, in runcode
    exec(code, self.locals)
  File "<pyshell#35>", line 1, in <module>
  File "/home/pedro/.local/lib/python3.10/site-packages/pandas/core/generic.py", line 5902, in __getattr__
    return object.__getattribute__(self, name)
AttributeError: 'Series' object has no attribute 'split'. Did you mean: 'plot'?
This works however, using your function find_supplier(description) :

supplier_table["Description"].map(find_supplier)
0     B
3     D
4     A
6     B
7     C
9     D
11    E
14    D
16    D
18    D
19    E
Name: Description, dtype: object
This, oddly, does not work, with the same AttributeError: 'Series' object has no attribute 'split'. Did you mean: 'plot'?:

intersection = set(description.split()) & suppliers
Traceback (most recent call last):
  File "/usr/lib/python3.10/idlelib/run.py", line 578, in runcode
    exec(code, self.locals)
  File "<pyshell#39>", line 1, in <module>
  File "/home/pedro/.local/lib/python3.10/site-packages/pandas/core/generic.py", line 5902, in __getattr__
    return object.__getattribute__(self, name)
AttributeError: 'Series' object has no attribute 'split'. Did you mean: 'plot'?
So, because your code works, you CAN split() description, AND you shouldn't be able to split() description!
Reply


Messages In This Thread
Fix pandas copy/slice warning. - by deanhystad - Sep-07-2023, 04:16 AM
RE: Fix pandas copy/slice warning. - by Pedroski55 - Sep-07-2023, 06:28 AM
RE: Fix pandas copy/slice warning. - by snippsat - Sep-07-2023, 07:12 AM
RE: Fix pandas copy/slice warning. - by deanhystad - Sep-07-2023, 03:18 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Why is the copy method name in python list copy and not `__copy__`? YouHoGeon 2 373 Apr-04-2024, 01:18 AM
Last Post: YouHoGeon
  Dataframe copy warning sawtooth500 4 495 Mar-25-2024, 11:38 PM
Last Post: sawtooth500
  Slice creates new objects? fmr300 4 1,414 Jul-20-2022, 12:34 PM
Last Post: fmr300
  InvalidIndexError: (slice(None, None, None), slice(None, -1, None)) SuperNinja3I3 1 4,667 Jul-15-2022, 05:59 AM
Last Post: Larz60+
  Slice list Moris526 1 1,711 Dec-24-2020, 02:19 AM
Last Post: deanhystad
  increase and decrease a slice value? KEYS 2 2,173 Nov-10-2020, 11:35 PM
Last Post: KEYS
  Pass Tuple as a Slice nagymusic 2 2,433 Dec-12-2019, 04:42 AM
Last Post: nagymusic
  Preferred way to slice a list SvetlanaofVodianova 3 2,635 Dec-09-2019, 11:50 PM
Last Post: SvetlanaofVodianova
  slice python array on condition Gigux 2 2,337 Nov-03-2019, 07:21 PM
Last Post: Larz60+
  How to append and drop to next line while slice/indexing emryscass 3 2,717 Sep-26-2019, 01:06 PM
Last Post: Malt

Forum Jump:

User Panel Messages

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