I have a .dat file which I read using df = pd.read_table('file.dat', sep='\s+')
and then I am supposed to select rows in the df (based on some condition) and write those to a new .dat file, now I tried using df.to_csv('newfile.dat', sep='\s+')
`import pandas as pd
df = pd.read_table('file.dat', sep='\s+')
selection = df[(df.hr >= 19) & (df.hr <= 24)]
selection.to_csv('newfile.dat, sep='\s+')`
but I get the error TypeError: "delimeter" must be an 1-character string
. After some googling I came to this solution
`import pandas as pd
df = pd.read_table('file.dat', sep='\s+')
selection = df[(df.hr >= 19) & (df.hr <= 24)]
file = open('newfile.dat', 'w+')
file.write(str(selection))`
but my file is so large that when it is saved on the document, it is saved along with the three dots '...' that shows there is more data here, it does not show the actual data
I don't know how I can write to a .dat file and keep the delimiter '\s+', any help is appreciated. Thank you.