I everyone, I've gotten the dreaded "A value is trying to be set on a copy of a slice from a DataFrame." error.
I saw a possible solution here How to deal with SettingWithCopyWarning in Pandas but it doesn't work with my example, since I'm trying to also use strip().
In a df with several columns, the type of "column_X" is object. I plan on later changing the strings to floats or integers. Currently, some values have a period followed by one or two zeros. So I want to strip everything starting from the period.
column_x | column_y |
---|---|
"1.00" | 35 |
"15.0" | 456 |
"2.00" | 32 |
"35.00" | 789 |
Here's my code:
df['column_x'] = df['column_x'].map(lambda x: x.strip('.'))
Desired output:
column_x | column_y |
---|---|
"1" | 35 |
"15" | 456 |
"2" | 32 |
"35" | 789 |
Actual output:
"A value is trying to be set on a copy of a slice from a DataFrame. Try using .loc[row_indexer,col_indexer] = value instead"
I'm not sure how to use .loc because most examples seem to have conditions while my code uses .strip() while mapping.
Any help would be greatly appreciated!