How to separate data into individual columns.

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Yifei
    New Member
    • Oct 2010
    • 1

    How to separate data into individual columns.

    Hello,

    I have a set of data that looks like this:

    044717.50-690930.3 -0.236
    ....
    ....

    I want to be able to separate the data into just
    044717.50 and 690930.3, ignoring the -0.236.

    I'm not really sure how to approach this problem as I am a beginner in Python usage.

    If it is possible, can you guys help me started with a sample code? Thanks so much!
  • bvdet
    Recognized Expert Specialist
    • Oct 2006
    • 2851

    #2
    That can easily be done like this:
    Code:
    >>> s = '044717.50-690930.3    -0.236\n'
    >>> values = [item.strip() for item in s.split('-')][:2]
    >>> values
    ['044717.50', '690930.3']
    >>>
    I am assuming the dash character will always be there to split the string into individual numbers. They are still strings, so you can type cast them to float if needed.
    Code:
    [float(item.strip()) for item in s.split('-')][:2]

    Comment

    Working...