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.
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.
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)