OiO.lk Community platform!

Oio.lk is an excellent forum for developers, providing a wide range of resources, discussions, and support for those in the developer community. Join oio.lk today to connect with like-minded professionals, share insights, and stay updated on the latest trends and technologies in the development field.
  You need to log in or register to access the solved answers to this problem.
  • You have reached the maximum number of guest views allowed
  • Please register below to remove this limitation

Polars datime_range with multiple values per date

  • Thread starter Thread starter user24900119
  • Start date Start date
U

user24900119

Guest
I'm trying to assign multiple entries from a list per date to my dateframe, so for each day, I would have all the values from the list. I tried passing the list as an argument; however, I'm having problems with the length of the dataframe.

Conceptual code:

Code:
from datetime import datetime
import polars as pl

Value_list = ["xd","xd1"]
dates_df= pl.DataFrame(
    {
        "dates": pl.datetime_range(
            start=datetime(2023, 1, 1),
            end=datetime(2023, 12, 10),
            interval="1d",
            eager=True,
            closed="both",
        ),
         "Producto": Value_list
    }
)
dates_df

My actual code:

Code:
from datetime import datetime
import polars as pl
dates_df= pl.DataFrame(
    {
        "dates": pl.datetime_range(
            start=datetime(2023, 1, 1),
            end=datetime(2023, 12, 10),
            interval="1d",
            eager=True,
            closed="both",
        ),
         "Producto": "xd"
    }
)
dates_df

Expected Output:

Code:
shape: (344, 2)
┌─────────────────────┬──────────┐
│ dates               ┆ Producto │
│ ---                 ┆ ---      │
│ datetime[μs]        ┆ str      │
╞═════════════════════╪══════════╡
│ 2023-01-01 00:00:00 ┆ xd       │
│ 2023-01-01 00:00:00 ┆ xd1      │
│ 2023-01-02 00:00:00 ┆ xd       │
│ 2023-01-02 00:00:00 ┆ xd1      │
│ 2023-01-03 00:00:00 ┆ xd       │
│ …                   ┆ …        │
│ 2023-12-08 00:00:00 ┆ xd1      │
│ 2023-12-09 00:00:00 ┆ xd       │
│ 2023-12-09 00:00:00 ┆ xd1      │
│ 2023-12-10 00:00:00 ┆ xd       │
│ 2023-12-10 00:00:00 ┆ xd1      │
└─────────────────────┴──────────┘
<p>I'm trying to assign multiple entries from a list per date to my dateframe, so for each day, I would have all the values from the list. I tried passing the list as an argument; however, I'm having problems with the length of the dataframe.</p>
<p>Conceptual code:</p>
<pre><code>from datetime import datetime
import polars as pl

Value_list = ["xd","xd1"]
dates_df= pl.DataFrame(
{
"dates": pl.datetime_range(
start=datetime(2023, 1, 1),
end=datetime(2023, 12, 10),
interval="1d",
eager=True,
closed="both",
),
"Producto": Value_list
}
)
dates_df
</code></pre>
<p>My actual code:</p>
<pre><code>from datetime import datetime
import polars as pl
dates_df= pl.DataFrame(
{
"dates": pl.datetime_range(
start=datetime(2023, 1, 1),
end=datetime(2023, 12, 10),
interval="1d",
eager=True,
closed="both",
),
"Producto": "xd"
}
)
dates_df

</code></pre>
<p>Expected Output:</p>
<pre><code>shape: (344, 2)
┌─────────────────────┬──────────┐
│ dates ┆ Producto │
│ --- ┆ --- │
│ datetime[μs] ┆ str │
╞═════════════════════╪══════════╡
│ 2023-01-01 00:00:00 ┆ xd │
│ 2023-01-01 00:00:00 ┆ xd1 │
│ 2023-01-02 00:00:00 ┆ xd │
│ 2023-01-02 00:00:00 ┆ xd1 │
│ 2023-01-03 00:00:00 ┆ xd │
│ … ┆ … │
│ 2023-12-08 00:00:00 ┆ xd1 │
│ 2023-12-09 00:00:00 ┆ xd │
│ 2023-12-09 00:00:00 ┆ xd1 │
│ 2023-12-10 00:00:00 ┆ xd │
│ 2023-12-10 00:00:00 ┆ xd1 │
└─────────────────────┴──────────┘
</code></pre>
 

Latest posts

Online statistics

Members online
0
Guests online
3
Total visitors
3
Ads by Eonads
Top