1
modified_symboltable = open('NYSE_Modified.csv', mode='w')

data1 = pd.DataFrame(pd.read_csv('NYSE_symbols.csv', sep=',', header='infer', index_col=None, usecols=[0, 1]))

print(data1)

modified_symboltable.write(str(data1))

Orignial data 'NYSE_symbols.csv' contains 3144 stock symbol data plus price data. What I want to do here is to isolate only symbols and names and write it to a different file for later use. But I cannot write everything on a 'modified_symboltable.csv', but instead it keeps writing the first 30 and the last 30 data only. What can I do here? I could not find any solution elsewhere. Many thanks

3
  • Not sure what you're trying to do, but you can just create a csv using data1.to_csv(file.csv). Commented Aug 5, 2017 at 7:24
  • Thanks.. Realized how noob I am... Such a simple solution there Commented Aug 5, 2017 at 7:27
  • Happy to help... we were all once the same. Anyways, feel free to mark my answer accepted when you can. Commented Aug 5, 2017 at 7:31

1 Answer 1

1
  1. Do not call str(df), it returns the string representation of the data frame, which is by default, the first and last 30 rows.

  2. Do not write a dataframe to a file using file.write. There are easier ways.


Use df.to_csv instead.

data1.to_csv('NYSE_Modified.csv')
Sign up to request clarification or add additional context in comments.

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.