-2

I need to remove the initial space from lines, like show below:

From

(space)09/Mar/21 16,997,520.6

To

09/Mar/21 16,997,520.6

I've tryed this : remove spaces from beginning of lines , but removed all spaces.

  • Does this answer your question? [How do I remove leading whitespace in Python?](https://stackoverflow.com/questions/959215/how-do-i-remove-leading-whitespace-in-python) – Ani Mar 10 '21 at 22:44

3 Answers3

0

Assuming from your question that you have a file loaded, with multiple lines (where 09/Mar/21 16,997,520.6 is one of those lines). Have you tried something like:

for line in file:
    line = line.strip()
    <--- Do stuff with the line --->
Niels Henkens
  • 2,553
  • 1
  • 12
  • 27
0

Use .lstrip(' ')

string = '    09/Mar/21 16,997,520.6'

print(string.lstrip(' '))

>>> 09/Mar/21 16,997,520.6

.lstrip() method will remove whatever is passed into it at the beginning of string.

For example:

print(string.lstrip(' 09'))
>>> /Mar/21 16,997,520.6
nahar
  • 41
  • 5
0

python

" 09/Mar/21 16,997,520.6".lstrip()

or pandas specific

df = pd.DataFrame([" 09/Mar/21 16,997,520.6"], columns = ['dummy_column'])
df['dummy_column'].str.lstrip()
Inrx
  • 13
  • 3