2
$\begingroup$

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.

EDIT2:

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]&]
$\endgroup$

closed as off-topic by WReach, MarcoB, Feyre, happy fish, Sascha Nov 23 '16 at 10:15

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "This question arises due to a simple mistake such as a trivial syntax error, incorrect capitalization, spelling mistake, or other typographical error and is unlikely to help any future visitors, or else it is easily found in the documentation." – WReach, MarcoB, Feyre, happy fish, Sascha
If this question can be reworded to fit the rules in the help center, please edit the question.

  • 1
    $\begingroup$ What about using quotes about the key name? $\endgroup$ – Sjoerd C. de Vries Nov 21 '16 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. Nov 21 '16 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 Nov 21 '16 at 20:21
  • 3
    $\begingroup$ I enter data[All, Append[#, "newPSI" -> #"PS_I"*3] &] with your definition of data and it works: i.stack.imgur.com/3Yhs2.png $\endgroup$ – Jason B. Nov 21 '16 at 20:22
  • 1
    $\begingroup$ @triplebig - can you paste the CSV contents into pastebin.com and give the URL here? $\endgroup$ – Jason B. Nov 21 '16 at 20:27

Browse other questions tagged or ask your own question.