Append Table by Columns Instead of Rows

Hi everyone,

Is there a way to append new columns to a pre-existing .csv file that already contains other columns?

For example, in the beginning of my method, I created File1 to write data into columns X, Y, and Z. Toward the end of the method, I want to reopen File1 and write data into another set of columns labeled as A, B, and C, starting from the first row again.

When I step up my protocol like that, an error occurs since the columns in both instances of opening File1 are not in “same” order for Venus to read from.

I then tried to define all of the columns in the first time of creating File1. That way, I would write in the variables in columns X, Y, and Z and then write in the variables in columns A, B, and C afterward. However, my file ends up looking something like this:

Screen Shot 2024-07-24 at 11.10.27 AM

When I want this instead:

Screen Shot 2024-07-24 at 11.09.58 AM

I found one way to accomplish this type of append mode by merging two tables into one.

However, I was wondering if it is possible to accomplish the same thing without having to create multiple sub-files. Basically, to work with one file alone.

Any help greatly appreciated,

-Nat

Hi @Nat,

Unfortunately, what you are experiencing here is a limitation of structured text files (i.e. .csv/.txt). If you wish to continue to use .csv files, then the techniques shown in the post you linked are your best option. The only way to use a single file would be to store all of the data in arrays from the start of the run until the end, and write all the data at once.

Alternatively, if you were to use an Excel file or Access database, then you could use SQL commands to JOIN tables or UPDATE cells, which is also noted in the post you linked.

Thank you,
Dan

1 Like

Thank you for the clarification as well as providing alternatives! I am testing out the option of first creating my two files (sheets) in .xls, merging them together, and then converting the merged file as a .csv. However, I am curious on how the JOIN SQL command is structured since I can’t find much information here on the forum.

Edit: Nevermind on the question since I misinterpreted the use case of the JOIN command. The JOIN command works when two separate table shares a column. The tables I have in mind do not share any columns but I believe there is one column that they can share.

Apologies for the hassle,

Does the JOIN command depend on the version of Excel we have? I am following the example linked in the original post and, although I am not running into any errors, my two tables are still unmerged at the end. I made other modifications to try to resolve the issue but to no avail. I could be missing something but here is my method for my test run (alongside the two tables I want to merge based on “number”).

SQL_command = “SELECT [map].[number], [name] FROM [map] INNER JOIN [report] ON [map].[number] = [report].[number]”

Screen Shot 2024-07-25 at 2.55.27 PMScreen Shot 2024-07-25 at 2.46.25 PM

If you are comfortable with python, this is relatively easy to do with pandas

1 Like

Now that you mentioned it, I don’t know why I didn’t think of that! Granted I wasn’t aware that it was possible using python script. Only having some experience creating and executing simple scripts in Venus. Well time to experiment on this more :eyes:

1 Like