0

when i pass to_string to a filter dataframe this generates a blank space in the output, I need the string without spaces.

this is the code:

df2['ETS'][df2['APPOINTMENT'] == appointment].to_string(index=False)

output:

' 10/19/2019'

output

salem1992
  • 75
  • 8
  • 1
    Try `df2.loc[df2['APPOINTMENT'] == appointment, 'ETS'].str.strip().to_string(index=False)` or `df2.loc[df2['APPOINTMENT'] == appointment, 'ETS'].to_string(index=False).strip()` – cs95 Oct 26 '19 at 19:42
  • Avoid chained assignments. https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html & https://stackoverflow.com/questions/21463589/pandas-chained-assignments – Alexander Oct 26 '19 at 19:45
  • This space might be coming from the source data. If it is unavoidable or can't control the source then do what cs95 proposes – S.N Oct 26 '19 at 19:45
  • @cs95 .strip() works great!!, but now how i can delete the ' ' of the output: '10/19/2019' – salem1992 Oct 26 '19 at 19:50
  • @salem1992 IPython will print out the repr by default (including the quotes), wrap the entire expression within `print(...)` and it will print the string without quotes. – cs95 Oct 26 '19 at 19:51

0 Answers0