I am opening a txt file using pandas and where there should be a column break in the file there is a \t
instead.
I am reading in the file like this:
df=pd.read_csv(r'file.txt')
The dataframe looks like this:
1 Band 1\t 0.428944\t0.843916\t0.689923\t0
2 Band 2\t-0.000000\t0.689320\t0.513170\t0
3 Band 3\t 0.336438\t0.743478\t0.592622\t0
4 Band 4\t 0.313259\t0.678561\t0.525667\t0
5 Band 5\t 0.374522\t0.746828\t0.583513\t0
and I want it to look like this:
1 Band 1 0.428944 0.843916 0.689923
2 Band 2 -0.000000 0.689320 0.513170
3 Band 3 0.336438 0.743478 0.592622
4 Band 4 0.313259 0.678561 0.525667
5 Band 5 0.374522 0.746828 0.583513
I am new to using txt files in python, do I perhaps have to set a delimiter of some sort?
Using print(repr(open(r'D:\Sheyenne\Statistics\NDVI_allotment\Text\A_Annex2.txt').read(42)))
returns:
'\n\n Band 1\t 0.428944\t0.843916\t0.689923\t
EDIT:
The original dataframes I posted are simplified and in reality there are more columns of data.
`print(repr(open(r'D:\Sheyenne\Statistics\NDVI_allotment\Text\A_Annex2.csv').read(500)))
returns:
'\nBasic Stats\t Min\t Max\t Mean\t Stdev\t Num\tEigenvalue\n Band 1\t 0.428944\t0.843916\t0.689923\t0.052534\t 1\t 0.229509\n Band 2\t-0.000000\t0.689320\t0.513170\t0.048885\t 2\t 0.119217\n Band 3\t 0.336438\t0.743478\t0.592622\t0.052544\t 3\t 0.059111\n Band 4\t 0.313259\t0.678561\t0.525667\t0.048047\t 4\t 0.051338\n Band 5\t 0.374522\t0.746828\t0.583513\t0.055989\t 5\t 0.027913\n Band 6\t-0.000000\t0.749325\t0.330068\t0.314351\t 6\t 0.022561\n Band 7\t-0.000000\t0.819288\t0.6001'