Aug-24-2018, 07:34 PM
I have a small 2D array which I am trying to save to csv such that when read will be identical to he original array.
I can remove headers, but not the index column.
Pre rcovery
0 1 2 3
0 A B C D
1 2 12 65 Plc
2 24 41 67 Plc
Post rcovery
A B C D
0 2 12 65 Plc
1 24 41 67 Plc
Whereas I an hoping for
Post rcovery
A B C D
2 12 65 Plc
24 41 67 Plc
I have trawled the net and forums without success - but it has to be a very simple solution ???
Any help greatly appreciated.
Astrikor
I can remove headers, but not the index column.
import csv import numpy as np import pandas as pd Results = np.array([['A','B','C','D'], [2,12,65,'Plc'], [24,41,67,'Plc']]) df = pd.DataFrame(Results) print('Pre rcovery') print(df) print() print() #save to csv: df.to_csv('Results39.csv', header=None, index=None) #recover from csv: df2 = pd.read_csv('Results39.csv') print('Post rcovery') print(df2)The result on running the file is as follows:
Pre rcovery
0 1 2 3
0 A B C D
1 2 12 65 Plc
2 24 41 67 Plc
Post rcovery
A B C D
0 2 12 65 Plc
1 24 41 67 Plc
Whereas I an hoping for
Post rcovery
A B C D
2 12 65 Plc
24 41 67 Plc
I have trawled the net and forums without success - but it has to be a very simple solution ???
Any help greatly appreciated.
Astrikor