Skip to content

SettingWithCopyWarning for string manipulation in dataframes with a non-monotonic index #6025

Closed
@egrublyte

Description

@egrublyte

Hi,

I get a SettingWithCopyWarning for string manipulation in dataframes with a non-monotonic index.

SettingWithCopyWarning: A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_index,col_indexer] = value instead

This only happens if the integer index skips a value. The code to reproduce:

from pandas import DataFrame
# create example dataframe:
df = DataFrame ({'column1':['a', 'a', 'a'], 'column2': [4,8,9] })
df
# assign string to 'column1':
df['column1'] = df['column1'] + 'b'
df
# it works just fine - no warnings
#now remove one line from dataframe df:
df = df [df['column2']!=8]
df
# adding string to 'column1' gives warning:
df['column1'] = df['column1'] + 'c'
df

NB: this only happens after a fresh login into python; if you run it again, it will not appear any more (!)

System:

  • Pandas 0.13
  • Python 2.7.2
  • Ubuntu 12.04LTS 64bit

Is this is an actual issue or just a nonsensical warning?

Kind regards,
Egle

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions