Swap values within classes
How can I swap values within classes please?
As shown in this table:
- - - - - - - - - - Before - - - - - - - - - - - - - - - - - - After - - - - - - - - - -

I want to do this because it is over sampled data. It is very repetitive and this causes machine learning tools to over fit.
pandas discrete-mathematics
add a comment |
How can I swap values within classes please?
As shown in this table:
- - - - - - - - - - Before - - - - - - - - - - - - - - - - - - After - - - - - - - - - -

I want to do this because it is over sampled data. It is very repetitive and this causes machine learning tools to over fit.
pandas discrete-mathematics
Why are you swapping those particular values? There are other rows of class=3, how come you're choosing not to edit/swap any of those ones?
– Thomas Kimber
Nov 23 '18 at 10:47
I would like to be able to vary how many values are swapped
– R. Cox
Nov 23 '18 at 10:56
And are you randomly swapping values row-wise, for a single column, or might you also want to switch values along other columns as well? Might there not be some correlation between the edited column and other columns in the data, and don't you run the risk of polluting the information by randomising it in this way? In the example you show, the column 1 swap makes no effective difference since the remaining column values are all the same in both instances. So in this case, a swap has zero effect, other than to essentially re-order the rows. That could just be an artifact of your example.
– Thomas Kimber
Nov 23 '18 at 11:14
Yes I would like to switch values along other columns as well please.
– R. Cox
Nov 23 '18 at 12:16
Yes that is an artefact of my example; swapping the values would not always have no effect.
– R. Cox
Nov 23 '18 at 12:17
add a comment |
How can I swap values within classes please?
As shown in this table:
- - - - - - - - - - Before - - - - - - - - - - - - - - - - - - After - - - - - - - - - -

I want to do this because it is over sampled data. It is very repetitive and this causes machine learning tools to over fit.
pandas discrete-mathematics
How can I swap values within classes please?
As shown in this table:
- - - - - - - - - - Before - - - - - - - - - - - - - - - - - - After - - - - - - - - - -

I want to do this because it is over sampled data. It is very repetitive and this causes machine learning tools to over fit.
pandas discrete-mathematics
pandas discrete-mathematics
asked Nov 23 '18 at 10:45
R. CoxR. Cox
12111
12111
Why are you swapping those particular values? There are other rows of class=3, how come you're choosing not to edit/swap any of those ones?
– Thomas Kimber
Nov 23 '18 at 10:47
I would like to be able to vary how many values are swapped
– R. Cox
Nov 23 '18 at 10:56
And are you randomly swapping values row-wise, for a single column, or might you also want to switch values along other columns as well? Might there not be some correlation between the edited column and other columns in the data, and don't you run the risk of polluting the information by randomising it in this way? In the example you show, the column 1 swap makes no effective difference since the remaining column values are all the same in both instances. So in this case, a swap has zero effect, other than to essentially re-order the rows. That could just be an artifact of your example.
– Thomas Kimber
Nov 23 '18 at 11:14
Yes I would like to switch values along other columns as well please.
– R. Cox
Nov 23 '18 at 12:16
Yes that is an artefact of my example; swapping the values would not always have no effect.
– R. Cox
Nov 23 '18 at 12:17
add a comment |
Why are you swapping those particular values? There are other rows of class=3, how come you're choosing not to edit/swap any of those ones?
– Thomas Kimber
Nov 23 '18 at 10:47
I would like to be able to vary how many values are swapped
– R. Cox
Nov 23 '18 at 10:56
And are you randomly swapping values row-wise, for a single column, or might you also want to switch values along other columns as well? Might there not be some correlation between the edited column and other columns in the data, and don't you run the risk of polluting the information by randomising it in this way? In the example you show, the column 1 swap makes no effective difference since the remaining column values are all the same in both instances. So in this case, a swap has zero effect, other than to essentially re-order the rows. That could just be an artifact of your example.
– Thomas Kimber
Nov 23 '18 at 11:14
Yes I would like to switch values along other columns as well please.
– R. Cox
Nov 23 '18 at 12:16
Yes that is an artefact of my example; swapping the values would not always have no effect.
– R. Cox
Nov 23 '18 at 12:17
Why are you swapping those particular values? There are other rows of class=3, how come you're choosing not to edit/swap any of those ones?
– Thomas Kimber
Nov 23 '18 at 10:47
Why are you swapping those particular values? There are other rows of class=3, how come you're choosing not to edit/swap any of those ones?
– Thomas Kimber
Nov 23 '18 at 10:47
I would like to be able to vary how many values are swapped
– R. Cox
Nov 23 '18 at 10:56
I would like to be able to vary how many values are swapped
– R. Cox
Nov 23 '18 at 10:56
And are you randomly swapping values row-wise, for a single column, or might you also want to switch values along other columns as well? Might there not be some correlation between the edited column and other columns in the data, and don't you run the risk of polluting the information by randomising it in this way? In the example you show, the column 1 swap makes no effective difference since the remaining column values are all the same in both instances. So in this case, a swap has zero effect, other than to essentially re-order the rows. That could just be an artifact of your example.
– Thomas Kimber
Nov 23 '18 at 11:14
And are you randomly swapping values row-wise, for a single column, or might you also want to switch values along other columns as well? Might there not be some correlation between the edited column and other columns in the data, and don't you run the risk of polluting the information by randomising it in this way? In the example you show, the column 1 swap makes no effective difference since the remaining column values are all the same in both instances. So in this case, a swap has zero effect, other than to essentially re-order the rows. That could just be an artifact of your example.
– Thomas Kimber
Nov 23 '18 at 11:14
Yes I would like to switch values along other columns as well please.
– R. Cox
Nov 23 '18 at 12:16
Yes I would like to switch values along other columns as well please.
– R. Cox
Nov 23 '18 at 12:16
Yes that is an artefact of my example; swapping the values would not always have no effect.
– R. Cox
Nov 23 '18 at 12:17
Yes that is an artefact of my example; swapping the values would not always have no effect.
– R. Cox
Nov 23 '18 at 12:17
add a comment |
1 Answer
1
active
oldest
votes
OK, try this out:
# Setup example dataframe
df = pd.DataFrame({"Class" : [1,2,1,3,1,2,1,3,1,2,1,3,1,2,1,3],
1:[1,1,1,0,1,0,1,0,1,0,1,0,1,0,1,1],
2:[0,1,0,0,0,1,0,0,0,1,0,0,0,1,0,0],
3:[0,0,1,1,1,0,1,1,0,0,1,1,1,0,1,1],
4:[1,0,1,1,1,0,1,1,1,0,1,1,1,0,1,1],
5:[0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1],
6:[0,0,0,1,0,0,0,1,0,0,0,1,0,0,0,1]}).set_index("Class")
# Do a filter on class, and store the positions/index of matching contents
class_to_edit=3
swappable_indices = np.where(df.index==class_to_edit)[0]
# Extract the column to edit
column_to_edit=1
column_values = df[column_to_edit].values
# Decide how many values to swap, and randomly assign swaps
# No guarantee here that the swaps will not contain the same values i.e. you could
# end up swapping 1's for 1's and 0's for 0's here - it's entirely random.
number_of_swaps = 2
swap_pairs = np.random.choice(swappable_indices,number_of_swaps*2, replace=False)
# Using the swap pairs, build a map of substitutions,
# starting with a vanilla no-swap map, then updating it with the generated swaps
swap_map={e:e for e in range(0,len(column_values))}
swap_map.update({swappable_indices[e]:swappable_indices[e+1] for e in range(0,len(swap_pairs),2)})
swap_map.update({swappable_indices[e+1]:swappable_indices[e] for e in range(0,len(swap_pairs),2)})
# Having built the swap-map, apply it to the data in the column,
column_values=[column_values[swap_map[e]] for e,v in enumerate(column_values)]
# and then plug the column back into the dataframe
df[column_to_edit]=column_values
It's a bit grubby, and I'm sure there's a cleaner way to build that substitution map in perhaps a one-line list comprehension - but that should do the trick.
Alternately, there's the np.permute function which might bear some fruit in terms of adding some noise (albeit not by performing discrete swaps).
[edit] For testing, try a dataset with a bit less rigidity, here's an example of a more randomly generated one. Just edit out the columns you want to replace with fixed values if you want to impose some order in the dataset.
df = pd.DataFrame({"Class" : [1,2,1,3,1,2,1,3,1,2,1,3,1,2,1,3],
1:np.random.choice([0,1],16),
2:np.random.choice([0,1],16),
3:np.random.choice([0,1],16),
4:np.random.choice([0,1],16),
5:np.random.choice([0,1],16),
6:np.random.choice([0,1],16)}).set_index("Class")
Sorry I thought that worked but when I change column_to_edit=6 it doesn't change it. I can see that it should sometimes not change it but I did try it a few times.
– R. Cox
Nov 23 '18 at 14:50
That's because using the provided data, when filtering on class=3, column 6 always contains a 1. Same for columns 3,4,5 and 6 in fact. And column 2 always contains a 0. Try it with a more randomised dataset. (edited answer to include one way of generating that for a test)
– Thomas Kimber
Nov 23 '18 at 14:59
add a comment |
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53445180%2fswap-values-within-classes%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
OK, try this out:
# Setup example dataframe
df = pd.DataFrame({"Class" : [1,2,1,3,1,2,1,3,1,2,1,3,1,2,1,3],
1:[1,1,1,0,1,0,1,0,1,0,1,0,1,0,1,1],
2:[0,1,0,0,0,1,0,0,0,1,0,0,0,1,0,0],
3:[0,0,1,1,1,0,1,1,0,0,1,1,1,0,1,1],
4:[1,0,1,1,1,0,1,1,1,0,1,1,1,0,1,1],
5:[0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1],
6:[0,0,0,1,0,0,0,1,0,0,0,1,0,0,0,1]}).set_index("Class")
# Do a filter on class, and store the positions/index of matching contents
class_to_edit=3
swappable_indices = np.where(df.index==class_to_edit)[0]
# Extract the column to edit
column_to_edit=1
column_values = df[column_to_edit].values
# Decide how many values to swap, and randomly assign swaps
# No guarantee here that the swaps will not contain the same values i.e. you could
# end up swapping 1's for 1's and 0's for 0's here - it's entirely random.
number_of_swaps = 2
swap_pairs = np.random.choice(swappable_indices,number_of_swaps*2, replace=False)
# Using the swap pairs, build a map of substitutions,
# starting with a vanilla no-swap map, then updating it with the generated swaps
swap_map={e:e for e in range(0,len(column_values))}
swap_map.update({swappable_indices[e]:swappable_indices[e+1] for e in range(0,len(swap_pairs),2)})
swap_map.update({swappable_indices[e+1]:swappable_indices[e] for e in range(0,len(swap_pairs),2)})
# Having built the swap-map, apply it to the data in the column,
column_values=[column_values[swap_map[e]] for e,v in enumerate(column_values)]
# and then plug the column back into the dataframe
df[column_to_edit]=column_values
It's a bit grubby, and I'm sure there's a cleaner way to build that substitution map in perhaps a one-line list comprehension - but that should do the trick.
Alternately, there's the np.permute function which might bear some fruit in terms of adding some noise (albeit not by performing discrete swaps).
[edit] For testing, try a dataset with a bit less rigidity, here's an example of a more randomly generated one. Just edit out the columns you want to replace with fixed values if you want to impose some order in the dataset.
df = pd.DataFrame({"Class" : [1,2,1,3,1,2,1,3,1,2,1,3,1,2,1,3],
1:np.random.choice([0,1],16),
2:np.random.choice([0,1],16),
3:np.random.choice([0,1],16),
4:np.random.choice([0,1],16),
5:np.random.choice([0,1],16),
6:np.random.choice([0,1],16)}).set_index("Class")
Sorry I thought that worked but when I change column_to_edit=6 it doesn't change it. I can see that it should sometimes not change it but I did try it a few times.
– R. Cox
Nov 23 '18 at 14:50
That's because using the provided data, when filtering on class=3, column 6 always contains a 1. Same for columns 3,4,5 and 6 in fact. And column 2 always contains a 0. Try it with a more randomised dataset. (edited answer to include one way of generating that for a test)
– Thomas Kimber
Nov 23 '18 at 14:59
add a comment |
OK, try this out:
# Setup example dataframe
df = pd.DataFrame({"Class" : [1,2,1,3,1,2,1,3,1,2,1,3,1,2,1,3],
1:[1,1,1,0,1,0,1,0,1,0,1,0,1,0,1,1],
2:[0,1,0,0,0,1,0,0,0,1,0,0,0,1,0,0],
3:[0,0,1,1,1,0,1,1,0,0,1,1,1,0,1,1],
4:[1,0,1,1,1,0,1,1,1,0,1,1,1,0,1,1],
5:[0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1],
6:[0,0,0,1,0,0,0,1,0,0,0,1,0,0,0,1]}).set_index("Class")
# Do a filter on class, and store the positions/index of matching contents
class_to_edit=3
swappable_indices = np.where(df.index==class_to_edit)[0]
# Extract the column to edit
column_to_edit=1
column_values = df[column_to_edit].values
# Decide how many values to swap, and randomly assign swaps
# No guarantee here that the swaps will not contain the same values i.e. you could
# end up swapping 1's for 1's and 0's for 0's here - it's entirely random.
number_of_swaps = 2
swap_pairs = np.random.choice(swappable_indices,number_of_swaps*2, replace=False)
# Using the swap pairs, build a map of substitutions,
# starting with a vanilla no-swap map, then updating it with the generated swaps
swap_map={e:e for e in range(0,len(column_values))}
swap_map.update({swappable_indices[e]:swappable_indices[e+1] for e in range(0,len(swap_pairs),2)})
swap_map.update({swappable_indices[e+1]:swappable_indices[e] for e in range(0,len(swap_pairs),2)})
# Having built the swap-map, apply it to the data in the column,
column_values=[column_values[swap_map[e]] for e,v in enumerate(column_values)]
# and then plug the column back into the dataframe
df[column_to_edit]=column_values
It's a bit grubby, and I'm sure there's a cleaner way to build that substitution map in perhaps a one-line list comprehension - but that should do the trick.
Alternately, there's the np.permute function which might bear some fruit in terms of adding some noise (albeit not by performing discrete swaps).
[edit] For testing, try a dataset with a bit less rigidity, here's an example of a more randomly generated one. Just edit out the columns you want to replace with fixed values if you want to impose some order in the dataset.
df = pd.DataFrame({"Class" : [1,2,1,3,1,2,1,3,1,2,1,3,1,2,1,3],
1:np.random.choice([0,1],16),
2:np.random.choice([0,1],16),
3:np.random.choice([0,1],16),
4:np.random.choice([0,1],16),
5:np.random.choice([0,1],16),
6:np.random.choice([0,1],16)}).set_index("Class")
Sorry I thought that worked but when I change column_to_edit=6 it doesn't change it. I can see that it should sometimes not change it but I did try it a few times.
– R. Cox
Nov 23 '18 at 14:50
That's because using the provided data, when filtering on class=3, column 6 always contains a 1. Same for columns 3,4,5 and 6 in fact. And column 2 always contains a 0. Try it with a more randomised dataset. (edited answer to include one way of generating that for a test)
– Thomas Kimber
Nov 23 '18 at 14:59
add a comment |
OK, try this out:
# Setup example dataframe
df = pd.DataFrame({"Class" : [1,2,1,3,1,2,1,3,1,2,1,3,1,2,1,3],
1:[1,1,1,0,1,0,1,0,1,0,1,0,1,0,1,1],
2:[0,1,0,0,0,1,0,0,0,1,0,0,0,1,0,0],
3:[0,0,1,1,1,0,1,1,0,0,1,1,1,0,1,1],
4:[1,0,1,1,1,0,1,1,1,0,1,1,1,0,1,1],
5:[0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1],
6:[0,0,0,1,0,0,0,1,0,0,0,1,0,0,0,1]}).set_index("Class")
# Do a filter on class, and store the positions/index of matching contents
class_to_edit=3
swappable_indices = np.where(df.index==class_to_edit)[0]
# Extract the column to edit
column_to_edit=1
column_values = df[column_to_edit].values
# Decide how many values to swap, and randomly assign swaps
# No guarantee here that the swaps will not contain the same values i.e. you could
# end up swapping 1's for 1's and 0's for 0's here - it's entirely random.
number_of_swaps = 2
swap_pairs = np.random.choice(swappable_indices,number_of_swaps*2, replace=False)
# Using the swap pairs, build a map of substitutions,
# starting with a vanilla no-swap map, then updating it with the generated swaps
swap_map={e:e for e in range(0,len(column_values))}
swap_map.update({swappable_indices[e]:swappable_indices[e+1] for e in range(0,len(swap_pairs),2)})
swap_map.update({swappable_indices[e+1]:swappable_indices[e] for e in range(0,len(swap_pairs),2)})
# Having built the swap-map, apply it to the data in the column,
column_values=[column_values[swap_map[e]] for e,v in enumerate(column_values)]
# and then plug the column back into the dataframe
df[column_to_edit]=column_values
It's a bit grubby, and I'm sure there's a cleaner way to build that substitution map in perhaps a one-line list comprehension - but that should do the trick.
Alternately, there's the np.permute function which might bear some fruit in terms of adding some noise (albeit not by performing discrete swaps).
[edit] For testing, try a dataset with a bit less rigidity, here's an example of a more randomly generated one. Just edit out the columns you want to replace with fixed values if you want to impose some order in the dataset.
df = pd.DataFrame({"Class" : [1,2,1,3,1,2,1,3,1,2,1,3,1,2,1,3],
1:np.random.choice([0,1],16),
2:np.random.choice([0,1],16),
3:np.random.choice([0,1],16),
4:np.random.choice([0,1],16),
5:np.random.choice([0,1],16),
6:np.random.choice([0,1],16)}).set_index("Class")
OK, try this out:
# Setup example dataframe
df = pd.DataFrame({"Class" : [1,2,1,3,1,2,1,3,1,2,1,3,1,2,1,3],
1:[1,1,1,0,1,0,1,0,1,0,1,0,1,0,1,1],
2:[0,1,0,0,0,1,0,0,0,1,0,0,0,1,0,0],
3:[0,0,1,1,1,0,1,1,0,0,1,1,1,0,1,1],
4:[1,0,1,1,1,0,1,1,1,0,1,1,1,0,1,1],
5:[0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1],
6:[0,0,0,1,0,0,0,1,0,0,0,1,0,0,0,1]}).set_index("Class")
# Do a filter on class, and store the positions/index of matching contents
class_to_edit=3
swappable_indices = np.where(df.index==class_to_edit)[0]
# Extract the column to edit
column_to_edit=1
column_values = df[column_to_edit].values
# Decide how many values to swap, and randomly assign swaps
# No guarantee here that the swaps will not contain the same values i.e. you could
# end up swapping 1's for 1's and 0's for 0's here - it's entirely random.
number_of_swaps = 2
swap_pairs = np.random.choice(swappable_indices,number_of_swaps*2, replace=False)
# Using the swap pairs, build a map of substitutions,
# starting with a vanilla no-swap map, then updating it with the generated swaps
swap_map={e:e for e in range(0,len(column_values))}
swap_map.update({swappable_indices[e]:swappable_indices[e+1] for e in range(0,len(swap_pairs),2)})
swap_map.update({swappable_indices[e+1]:swappable_indices[e] for e in range(0,len(swap_pairs),2)})
# Having built the swap-map, apply it to the data in the column,
column_values=[column_values[swap_map[e]] for e,v in enumerate(column_values)]
# and then plug the column back into the dataframe
df[column_to_edit]=column_values
It's a bit grubby, and I'm sure there's a cleaner way to build that substitution map in perhaps a one-line list comprehension - but that should do the trick.
Alternately, there's the np.permute function which might bear some fruit in terms of adding some noise (albeit not by performing discrete swaps).
[edit] For testing, try a dataset with a bit less rigidity, here's an example of a more randomly generated one. Just edit out the columns you want to replace with fixed values if you want to impose some order in the dataset.
df = pd.DataFrame({"Class" : [1,2,1,3,1,2,1,3,1,2,1,3,1,2,1,3],
1:np.random.choice([0,1],16),
2:np.random.choice([0,1],16),
3:np.random.choice([0,1],16),
4:np.random.choice([0,1],16),
5:np.random.choice([0,1],16),
6:np.random.choice([0,1],16)}).set_index("Class")
edited Nov 23 '18 at 15:01
answered Nov 23 '18 at 14:14
Thomas KimberThomas Kimber
3,46421324
3,46421324
Sorry I thought that worked but when I change column_to_edit=6 it doesn't change it. I can see that it should sometimes not change it but I did try it a few times.
– R. Cox
Nov 23 '18 at 14:50
That's because using the provided data, when filtering on class=3, column 6 always contains a 1. Same for columns 3,4,5 and 6 in fact. And column 2 always contains a 0. Try it with a more randomised dataset. (edited answer to include one way of generating that for a test)
– Thomas Kimber
Nov 23 '18 at 14:59
add a comment |
Sorry I thought that worked but when I change column_to_edit=6 it doesn't change it. I can see that it should sometimes not change it but I did try it a few times.
– R. Cox
Nov 23 '18 at 14:50
That's because using the provided data, when filtering on class=3, column 6 always contains a 1. Same for columns 3,4,5 and 6 in fact. And column 2 always contains a 0. Try it with a more randomised dataset. (edited answer to include one way of generating that for a test)
– Thomas Kimber
Nov 23 '18 at 14:59
Sorry I thought that worked but when I change column_to_edit=6 it doesn't change it. I can see that it should sometimes not change it but I did try it a few times.
– R. Cox
Nov 23 '18 at 14:50
Sorry I thought that worked but when I change column_to_edit=6 it doesn't change it. I can see that it should sometimes not change it but I did try it a few times.
– R. Cox
Nov 23 '18 at 14:50
That's because using the provided data, when filtering on class=3, column 6 always contains a 1. Same for columns 3,4,5 and 6 in fact. And column 2 always contains a 0. Try it with a more randomised dataset. (edited answer to include one way of generating that for a test)
– Thomas Kimber
Nov 23 '18 at 14:59
That's because using the provided data, when filtering on class=3, column 6 always contains a 1. Same for columns 3,4,5 and 6 in fact. And column 2 always contains a 0. Try it with a more randomised dataset. (edited answer to include one way of generating that for a test)
– Thomas Kimber
Nov 23 '18 at 14:59
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53445180%2fswap-values-within-classes%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown

Why are you swapping those particular values? There are other rows of class=3, how come you're choosing not to edit/swap any of those ones?
– Thomas Kimber
Nov 23 '18 at 10:47
I would like to be able to vary how many values are swapped
– R. Cox
Nov 23 '18 at 10:56
And are you randomly swapping values row-wise, for a single column, or might you also want to switch values along other columns as well? Might there not be some correlation between the edited column and other columns in the data, and don't you run the risk of polluting the information by randomising it in this way? In the example you show, the column 1 swap makes no effective difference since the remaining column values are all the same in both instances. So in this case, a swap has zero effect, other than to essentially re-order the rows. That could just be an artifact of your example.
– Thomas Kimber
Nov 23 '18 at 11:14
Yes I would like to switch values along other columns as well please.
– R. Cox
Nov 23 '18 at 12:16
Yes that is an artefact of my example; swapping the values would not always have no effect.
– R. Cox
Nov 23 '18 at 12:17