I have a dataset which has a column called "PS_I". I cannot change this because I imported the column from an existing csv.

I would like to add another column. Such as:

data = data[All, Append[#,"newPSI" -> #PS_I * 3]&]

But that doesn't work due to underscore being a predefined character.

How do I get around this?

EDIT: Here's an example.

This is one column with such an index:

data = Dataset[ {<|"PS_I" -> 1|>,
   <|"PS_I" -> 2|>,
   <|"PS_I" -> 3|>,
   <|"PS_I" -> 4|>,
   <|"PS_I" -> 5|>,
   <|"PS_I" -> 6|>,
   <|"PS_I" -> 7|>}]

And I want to create a new column with some operation on the values of the PS_I column. Kind of what this answer suggested: How can I add a column into a existing Dataset?

The underscore does not allow for these type of operations, and I would like to know how to deal with this problem.


Here's how to reproduce the problem, now with input from JasonB:

1) Create a csv with these contents: http://pastebin.com/eYUaW2bV

2) Run

data = SemanticImport["<pathtofolder>/example.csv"];

3) Try to append with

data = data[All, Append[#,"newPSI" -> #"PS_I" * 3]&]
  • 1
    $\begingroup$ What about using quotes about the key name? $\endgroup$ Commented Nov 21, 2016 at 20:10
  • 2
    $\begingroup$ Possible duplicate of Filtering of a Dataset based on a column name with underscore and a nested string pattern. You need to use #"PS_I" $\endgroup$
    – Jason B.
    Commented Nov 21, 2016 at 20:14
  • $\begingroup$ Hi JasonB, I found that topic but it did not help. Placing quotes around it gives me an error: "Key PS_I is not one of {..., PS_I,..}" $\endgroup$
    – triplebig
    Commented Nov 21, 2016 at 20:21
  • 3
    $\begingroup$ I enter data[All, Append[#, "newPSI" -> #"PS_I"*3] &] with your definition of data and it works: i.sstatic.net/3Yhs2.png $\endgroup$
    – Jason B.
    Commented Nov 21, 2016 at 20:22
  • 1
    $\begingroup$ @triplebig - can you paste the CSV contents into pastebin.com and give the URL here? $\endgroup$
    – Jason B.
    Commented Nov 21, 2016 at 20:27


Browse other questions tagged or ask your own question.