Comments (1)
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
╔════════════╤═══════════════════╤═══════════════════╤═══════════════════╤═══════════════════╗
║ │ A │ B │ C │ D ║
╟────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢
║ 10 │ 0.4612 │ 4.28283 │ -1.509 │ -1.1352 ║
╟────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢
║ 11 │ 0.5112 │ -0.22863 │ -3.39059 │ 1.1632 ║
╟────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢
║ 12 │ 0.6911 │ -0.82863 │ -1.5059 │ 2.1352 ║
╟────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢
║ 13 │ 0.4692 │ -1.28863 │ 4.5059 │ 4.1632 ║
╚════════════╧═══════════════════╧═══════════════════╧═══════════════════╧═══════════════════╝
startup:4
╔════════════╤═══════════════════╤═══════════════════╤═══════════════════╤═══════════════════╗
║ │ 10 │ 11 │ 12 │ 13 ║
╟────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢
║ A │ 0.4612 │ 0.5112 │ 0.6911 │ 0.4692 ║
╟────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢
║ B │ 4.28283 │ -0.22863 │ -0.82863 │ -1.28863 ║
╟────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢
║ C │ -1.509 │ -3.39059 │ -1.5059 │ 4.5059 ║
╟────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢
║ D │ -1.1352 │ 1.1632 │ 2.1352 │ 4.1632 ║
╚════════════╧═══════════════════╧═══════════════════╧═══════════════════╧═══════════════════╝
from danfojs.
Related Issues (20)
- missing to_dict("index")
- error: File format not supported! while trying to reassign a column.
- shift is missing for Series HOT 1
- Series to DataFrame HOT 3
- Unable to handle NA value from CSV HOT 1
- Replacing a value with 0 with dataframe.replace throws an error HOT 1
- after apply not able to set column
- query operator HOT 1
- df apply not working as expected
- development environment not working as per contribution guidelines
- merge has exponential complexity crashing the runtime
- Problem in installation HOT 2
- The node environment is incorrectly installed
- Sorting bug when NaN values exist HOT 3
- Methods in the documentation don't match the current lib status for browser
- dropNa not working HOT 3
- Issue with Retrieving Columns Named with Colon ':' in Single Selection Using danfojs-node
- Type Narrowing an object which is either dfd.Series or dfd.DataFrame to dfd.DataFrame HOT 1
- Concat behaviour differs significantly from pandas (column order dependent)
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from danfojs.