1

I would like to save down some panda dataframe downloads separately as csv files. I am getting an error in the last line.

Is the syntax off?

Kind regards

sortedByISIN = pd.DataFrame()

for i in data['isin'].unique():
 print('Adding ' + i)
 d1 = data[data['isin'] == i]

 d1['next_signal'] = d1['signal'].shift(-1)

 #Shift x periods in the future 
 d1['futprice'] = d1['mid'].shift(-6)
 d1['futT'] = d1['creationTimeStamp'].shift(-6)


 d1['move'] = d1.apply(lambda row: (row['futprice'] - row['mid'])/row['mid'] * 10000 if row['futT'] - row['creationTimeStamp'] < 300000 else 0, axis=1)
 d1['signal_transition'] = d1['next_signal'] - d1['signal']

 sortedByISIN = sortedByISIN.append(d1)

 sortedByISIN['period'] = np.floor(sortedByISIN.creationTimeStamp/3600000)
 sortedByISIN.to_csv('Book'%i.csv')
0

2 Answers 2

2

or you can use also:

sortedByISIN.to_csv('Book' + str(i) + '.csv')
Sign up to request clarification or add additional context in comments.

Comments

0

Use format:

sortedByISIN.to_csv('Book{}.csv'.format(i))

And for python 3.6+ is possible use f-strings:

sortedByISIN.to_csv(f'Book{i}.csv')

Comments

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.