-
-
Notifications
You must be signed in to change notification settings - Fork 210
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Transpose a DataFrame #618
Comments
Probably not the best solution... but it can give some ideas for a possible implementation of a transpose method for DataFrame. <!DOCTYPE html>
<html lang="en">
<head>
<title>MWE</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-T3c6CoIi6uLrA9TneNEoa7RxnatzjcDSCmG1MXxSR1GAsXEV/Dwwykc2MPK8M2HN" crossorigin="anonymous">
<body>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js" integrity="sha384-C6RzsynM9kWDrMNeT87bh95OGNyZPhcTNXj1NW7RuBCsyN/o0jlpcV8Qyq46cDfL" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/lib/bundle.min.js"></script>
<script>
(function(window, document, undefined) {
// code that should be taken care of right away
window.onload = init;
function transpose(df) {
array = df.values;
transposed_array = array[0].map((_, colIndex) => array.map(row => row[colIndex]));
return new dfd.DataFrame(transposed_array, {index: df.columns, columns: df.index});
}
function init() {
console.log("init");
json_data = [{ A: 0.4612, B: 4.28283, C: -1.509, D: -1.1352 },
{ A: 0.5112, B: -0.22863, C: -3.39059, D: 1.1632 },
{ A: 0.6911, B: -0.82863, C: -1.5059, D: 2.1352 },
{ A: 0.4692, B: -1.28863, C: 4.5059, D: 4.1632 }];
df = new dfd.DataFrame(json_data, {index: [10, 11, 12, 13]});
df.print();
transpose(df).print();
}
})(window, document, undefined);
</script>
<h1>MWE</h1>
</body>
</html> here is console output
|
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hello,
it would be nice to add a
transpose
method to DanfoJS DataFrame similar to https://pandas.pydata.org/docs/reference/api/pandas.DataFrame.transpose.htmlKind regards
The text was updated successfully, but these errors were encountered: