By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,767 Members | 2,114 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,767 IT Pros & Developers. It's quick & easy.

How to separate data into individual columns.

P: 1

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!
Oct 14 '10 #1
Share this Question
Share on Google+
1 Reply

Expert Mod 2.5K+
P: 2,851
That can easily be done like this:
Expand|Select|Wrap|Line Numbers
  1. >>> s = '044717.50-690930.3    -0.236\n'
  2. >>> values = [item.strip() for item in s.split('-')][:2]
  3. >>> values
  4. ['044717.50', '690930.3']
  5. >>> 
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.
Expand|Select|Wrap|Line Numbers
  1. [float(item.strip()) for item in s.split('-')][:2]
Oct 14 '10 #2

Post your reply

Sign in to post your reply or Sign up for a free account.