Closed scart888 closed 1 year ago
There are no methods defined right now for deleting columns or rows. Since you have a source CSV file, I would start with that. There are lots of tutorials on how to read CSV files like this one.
Here's something that would work:
from numbers_parser import Document
from csv import reader
doc = Document()
with open("test.csv") as csv_file:
csv_reader = reader(csv_file)
row_num = 0
table = doc.sheets[0].tables[0]
for row in csv_reader:
table.write(row_num, 0, row[1]) # write this row's column B
table.write(row_num, 1, row[3]) # write this row's column D
table.write(row_num, 2, row[5]) # write this row's column F
row_num += 1
doc.save("test.numbers")
Columns are numbered in numbers_parser
so B, D and F are columns 1, 3 and 5.
The number of columns and rows in a blank new document is fixed at the moment though I could add this in the future, which means you are likely to have blank rows and columns.
Doing it this way has the advantage that you can manipulate the data if you need to make changes. For example, if you want to categorise your transactions based on substring matches, you could have a separate CSV/Numbers file with the data in it and iterate through that looking for strings. That's obviously much more into programming, but it's all basic Python. Tutorials like this one will help you make progress.
Good luck, have fun!
Since this is not an issue as such, I will close.
Hi,
I have an issue printing FULL columns from my numbers spreadsheet into python. I want to be able to print specific columns (vertical) not just specific cells or the entire data.
e.g. On my bank transactions I have a CSV file i downloaded from my bank, it has a lot of unnecessary columns so I'm trying to select columns [B, D & F], import them into python & then export the data into another file. I would be happy with deleting the columns for now, but eventually I'd like it to be more powerful and able to export the full column.
I've attached the example code to print specific cells, which works perfectly. The problem is when I try to print an entire column it doesn't work. I CAN PRINT AN ENTIRE ROW but not a column. Here's the error code for for the code I'm using to delete a column:
Traceback (most recent call last): File "/myfilepath/myfile.py", line 11, in
table.delete_column([0, 2, 4])
^^^^^^^^^^^^^^^^^^^
AttributeError: 'Table' object has no attribute 'delete_column'
I'm not a programmer, so it's probably something simple I'm missing. This is all very new to me so please go easy on me if it's an easy solution. I have searched google, youtube & even chatGPT/bard for a while (which was painful) for a full list of attributes I can use for this apple numbers parser, but I cannot find anything other than the few examples listed on this page. I have tried to look at the code written here as I assumed it would be there, but after I scrolling through every file nothing was obvious to me as a novice. Is there a resource I can get that will tell me the full capabilities of this numbers_parser?
Any help at all would be massively appreciated. Thanks!