1

I am trying to append 10 , 5, 890, 50, Finish for the Date,High,Low,Volume,Symbol at the end of the input.csv file. It will format the contents of the csv file permanently so I use data.to_csv(url,index=False). How would I be able to do that?

import pandas as pd
url= 'input.csv'
data = pd.read_csv(url, low_memory=False)
data.to_csv(url,index=False)

Current output:

Date,High,Low,Volume,Symbol
2021-01-15 00:04:00,39358.98,39273.24,0.4786072902,BTCUSD
2021-01-15 00:03:00,39362.37,39166.19,0.2911817448,BTCUSD
2021-01-15 00:02:00,39187.06,39017.72,6.2488076695,BTCUSD

Expected output:

Date,High,Low,Volume,Symbol
2021-01-15 00:04:00,39358.98,39273.24,0.4786072902,BTCUSD
2021-01-15 00:03:00,39362.37,39166.19,0.2911817448,BTCUSD
2021-01-15 00:02:00,39187.06,39017.72,6.2488076695,BTCUSD
10 , 5, 890, 50, Finish 

1 Answer 1

1

Try with loc:

data = pd.read_csv(url, low_memory=False)

data.loc[len(data)] = [10 , 5, 890, 50, 'Finish' ]
data.to_csv(url,index=False)
Sign up to request clarification or add additional context in comments.

4 Comments

what is df supposed to be?
Oh, that's data. Usually we use df for dataframe.
oh I see thanks for the clarification is the purpose of the .loc function to read the rows?
@egeSelcuk ít can be used both to get and to set the values.

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.