Pandas is taylor made for this kind of processing. I strongly encourage you to use it.
For example you could do the first two things with one line of code.
Third thing would be:
data.NewTotal - data.Total - data.Costs
Fourth thing would be:
data[data.Type =="Buy"]
The couple of hours you might spend understanding how to use pandas for these basic things will pay dividends many times over.
For example you could do the first two things with one line of code.
Third thing would be:
data.NewTotal - data.Total - data.Costs
Fourth thing would be:
data[data.Type =="Buy"]
The couple of hours you might spend understanding how to use pandas for these basic things will pay dividends many times over.
Thanks for all the replies. I have included the actual CSV data I am using to give you a better idea how it is formatted. My objective is:
- Read the file line by line.
- Break each line at the comma into it's own column or index- index[0] index[1] index[2] ...... index[9]
- Preform basic math on some of the columns and put the results into a new column.
- Only use rows that match a certain criteria, such as: index[2] == Buy,Sell or Expired.
- Output only the columns I want to a new CSV file, also comma separated.
I have completed all of the above on one line hard coded into my script. Now I'm working on reading an entire file - line by line - then writing to a new file.
![]()