-1

uploaded csv file

there is a field named "price", which looks as follows below:

PRICE 
435         
303         
442         
497         
528         
... 
1 129,24    
1 129,24    
1 129,24    
1 129,24    
1 129,24    

I need to delete a space in a price 1 129,24.

I tried replace, converters, skipinitialspace, strip() - none of them helped

Andrej Kesely
  • 168,389
  • 15
  • 48
  • 91
Ksenia
  • 1
  • 2
  • 2
    Please add your attempts as code snippets – Daweo Apr 07 '23 at 18:09
  • 1
    `print('1 129,24'.replace(' ',''))` works just fine for me. – JNevill Apr 07 '23 at 18:11
  • 1
    What does the data look like in your CSV file? Are these being read as strings, or as numbers? If it possible that's the "standard" for your region? – Tim Roberts Apr 07 '23 at 18:16
  • Did you copy this from Excel or something? It might have formatted the numbers specially. Please make a [mre]. For specifics, see [How to make good reproducible pandas examples](/q/20109391/4518341). For other tips, check out [How to ask a good question](/help/how-to-ask). – wjandrea Apr 07 '23 at 18:17

1 Answers1

2

assuming it's a column 'price' within a dataframe df, this should work:

df['price'].str.replace(' ', '')

note this uses pd.Series.str to call string manipulation functions such as .replace() on each element of a Series

wjandrea
  • 28,235
  • 9
  • 60
  • 81
sha2fiddy
  • 45
  • 6