Comments (4)
Did you try align
instead of diagonal
?
df1 = pl.DataFrame({"date": [1, 2, 3], "usdeur": ["a", "b", "c"]})
df2 = pl.DataFrame({"date": [1, 2, 3], "abcdef": ["d", "e", "f"]})
df3 = pl.DataFrame({"date": [4, 5], "foobar": ["g", "h"]})
pl.concat([df1, df2, df3], how="align")
# shape: (5, 4)
# ┌──────┬────────┬────────┬────────┐
# │ date ┆ usdeur ┆ abcdef ┆ foobar │
# │ --- ┆ --- ┆ --- ┆ --- │
# │ i64 ┆ str ┆ str ┆ str │
# ╞══════╪════════╪════════╪════════╡
# │ 1 ┆ a ┆ d ┆ null │
# │ 2 ┆ b ┆ e ┆ null │
# │ 3 ┆ c ┆ f ┆ null │
# │ 4 ┆ null ┆ null ┆ g │
# │ 5 ┆ null ┆ null ┆ h │
# └──────┴────────┴────────┴────────┘
from polars.
Yeah, that's exactly what I needed lol
Sorry for the spam.
from polars.
Sorry, can you be clearer with an example? How does it have a known structure if the size is unknown? And if every column is different, how do you plan polars to figure out which columns you want to be considered "the same column"?
from polars.
Sorry if I wasn't clear. Here's an example:
Say my organization stores time series data in a warehouse and every series has a date column with name "date", but the value column is named differently according to the variable it represents. So a time series of the dollar-euro exchange rate would have columns "date" and "USDEUR". I might be tasked with writing a utility function for our in-house library that calculates statistics for an arbitrary list of time series.
When writing such a function, I am faced with the situation I described: I know that every dataframe will have a column named "date", yet I can't join them together in a single, wide DataFrame cleanly. The most efficient way I can think of is to pivot every Dataframe to a long format, have the value column named "value" with it's original name moved to a "variable" column, then vertically concat. But this seems wasteful, as in the end I'll probably want to pivot to the wider format again to make cross-sectional calculations.
I know this example could easily be solved by having the data stored a different way, I'm just trying to come up with a simple use case.
from polars.
Related Issues (20)
- Incorrect results from `Series.__rtruediv__` HOT 1
- Add SQL feature of ORDER BY RANDOM()
- Expressions support in insert_column (like with_columns)
- Passing a `Series` to `DataFrame.sort` gives "literal expressions are not allowed for sorting" error HOT 3
- polars' ingestion of decimal.Decimal values fails if all values do not have the same number of decimal places HOT 2
- Series.is_in called with a mixed list of Python integers and floats fails HOT 4
- Where is indexing `__getitem__` (e.g. `df[...]`) documented for polars DataFrame and Series? HOT 5
- Casting literal floats to strings rounds the value down. HOT 2
- Try-Except style Error handing for Column Computation?
- double select on lazyframe has performance regression HOT 1
- Join documentation is misleading or wrong. HOT 1
- Missing docs pages for some Series methods HOT 1
- DataFrame.__pow__ fails for (series, column) inputs HOT 1
- Request for Inequality operator to handle Null values as-well HOT 3
- Polars' rust parquet engine reads/writes files that are unreadable by duckdb/pandas/pyarrow `(use_pyarrow=True)` HOT 2
- `pl.cum_count` doesn't
- Transpose option for `DataFrame.describe()`
- Adding “Rounding half to even”
- `the name 'literal' is duplicate` when selecting a multi-element NumPy array or list
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 polars.