Been testing with some data management techniques with pandas and csv. What I'm trying to do is read a csv file, add some extra rows to it, and save again with identical format.
I've created a dataframe of shape (250, 20) with random values, dates as index and alphabets as columns then saved it as a csv file. Ultimately what I've tried is to append the same dataframe below an existing csv file.
def _writeBulk(savefile, data):
df = data.reset_index()
with open(savefile, 'w', newline='') as outfile:
writer = csv.writer(outfile)
writer.writerows(df.to_numpy().tolist())
outfile.close()
def _writeData(savefile, data):
df = data.reset_index()
with open(savefile, 'w', newline='') as outfile:
writer = csv.writer(outfile)
for row in range(df.shape[0]):
writer.writerow(df.iloc[row].tolist())
outfile.close()
When reading in the file again after edit, the result I'm expecting is a dataframe of shape (500,20). But it seems that the file does not have headers(columns) anymore, with shape (499, 200).
I've searched for solutions or explanations but skipping the header while writing rows is the closest I've ever got to the actual issue.
Any explanations or solutions would be appreciated.