0
import pandas as pd

url = 'https://m-selig.ae.illinois.edu/ads/coord/2032c.dat'
df =  pd.read_table(url, header=None, skiprows=2, sep=('\t'), engine='python')
df.to_excel('data_1.xlsx', index=False, header=False)

The url includes the x and y coordinates. When I make the url into an excel file the points are in a single column. How can I make it into two columns?

1 Answer 1

1

This should allow you to split the X and Y into 2 separate columns (I wasn't sure which was X and which was Y so you might need to change the column names a little)

url = 'https://m-selig.ae.illinois.edu/ads/coord/2032c.dat'
df =  pd.read_table(url, header=None, skiprows=2, sep=('\t'), engine='python')
df[0] = df[0].str.strip(' ')
df[['X', 'Y']] = df[0].str.split('  ', 1, expand = True)
df[['X', 'Y']]
Sign up to request clarification or add additional context in comments.

2 Comments

When I run that code It gives me three columns, the first column includes all the points. Second and Third where it splits correctly into X and Y coordinates. How can I get rid of the first column?
in the df[['X', 'Y']] you can replace that line with df = df[['X', 'Y']]

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.