0

I have text file:

 sn we 200 8.8 99.3 10 

I tried

np.genfromtxt(b[], delimiter=' ', dtype=None) 

I want to get numpay array or pandas data frame with 2 columns (This is coordinates). What is the easiest way to do it? Delimiter - tab.

1
  • Magic. Thank you. I can not add you score, butthank thank you Commented Oct 19, 2017 at 12:17

1 Answer 1

1

If you want a dataframe, call read_csv with delim_whitespace=True.

df = pd.read_csv('file.txt', delim_whitespace=True) 

Alternatively, specify a regex-based separator:

df = pd.read_csv('file.txt', sep='\s+') 

You also can retrieve a numpy array of values by querying df.values. Otherwise, you can directly retrieve a numpy array using np.loadtxt:

array = np.loadtxt('file.txt', skiprows=1) 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.