how to store data at row[0] in csv file

I am working on live data using python. I am storing the data in csv file and showing that data to user using dash data table. Because the daily data may be very long so it it difficult for user to scroll whole data every time to see the latest live data. So what I want to do is I want to store the newest data in csv at the very first row i.e on row[0]. So the current data will be displayed on top of the data table.

df = pd.read_csv("myfile.csv")
df = df.loc[::-1]

But as I said I am working on live data so it is reversing and re-reversing the csv every time when the data is coming.

Please help me to get the solution of my query Thanks in advance.

1

1 Answer

Not sure if I understand correctly, but:

If you want only to display first row:

df.query('index == 0')

If you want to add data at the first row:

df.loc[-1] = ['data1', 'data2', 'data3']
df.index = df.index + 1
df.sort_index(inplace=True)

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

You Might Also Like