-
-
Notifications
You must be signed in to change notification settings - Fork 209
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
Series to DataFrame #619
Comments
This is probably not the best approach but here is a solution <!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/bootstrap@5.3.2/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-T3c6CoIi6uLrA9TneNEoa7RxnatzjcDSCmG1MXxSR1GAsXEV/Dwwykc2MPK8M2HN" crossorigin="anonymous">
<body>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/js/bootstrap.bundle.min.js" integrity="sha384-C6RzsynM9kWDrMNeT87bh95OGNyZPhcTNXj1NW7RuBCsyN/o0jlpcV8Qyq46cDfL" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/danfojs@1.1.2/lib/bundle.min.js"></script>
<script>
(function(window, document, undefined) {
// code that should be taken care of right away
window.onload = init;
function row2col(row_array) {
col_array = []
row_array.forEach(function(row) {
col_array.push([row])
})
return col_array;
}
function toframe(ser, colname) {
df = new dfd.DataFrame(row2col(ser.values), { columns: [colname], index: ser.index });
return df
}
function init() {
console.log("init");
ser = new dfd.Series([10, 11, 12, 13], { index: ["a", "b", "c", "d"] });
ser.print();
df = toframe(ser, "NewCol");
df.print()
}
})(window, document, undefined);
</script>
<h1>MWE</h1>
</body>
</html> and console ouput
Maybe Series could have a method for that. Any opinion? |
Moreover if Series had a |
Moreover, in typescript, I'm unclear how to type narrow something to being a DataFrame, when we know it is not a Series df.constructor.name === "DataFrame" Both seem to be giving me issues |
Hello,
I don't know if it's a feature request or doc request... but I haven't found how to convert a Series to a DataFrame.
Similar to https://pandas.pydata.org/docs/reference/api/pandas.Series.to_frame.html
Kind regards
The text was updated successfully, but these errors were encountered: