A date column can be created in a Polars dataframe using the datetime
function which takes the year, month and day columns as input and creates a new column with the date format.
Here is an example:
import polars as pl
# Create a Polars dataframe with year, month and day columns
df = pl.DataFrame({
"year": [2021, 2021, 2021],
"month": [1, 2, 3],
"day": [10, 20, 30]
})
# Create a date column using the year, month and day columns
df = df.with_column(
pl.datetime(df['year'], df['month'], df['day']).alias('date')
)
print(df)
Output:
+------+------+-----+------------+
| year | month | day | date |
| --- | --- | --- | --- |
| i64 | i64 | i64 | datetime64 |
+======+======+======+============+
| 2021 | 1 | 10 | 2021-01-10 |
+------+------+-----+------------+
| 2021 | 2 | 20 | 2021-02-20 |
+------+------+-----+------------+
| 2021 | 3 | 30 | 2021-03-30 |
+------+------+-----+------------+
Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss
Asked: 2023-05-24 11:28:03 +0000
Seen: 18 times
Last updated: May 24 '23
How can I modify the week day format in the React datetime library from Su Mo to Sun, Mon?
Which day of the year is the first Friday?
What is the process for obtaining the timestamp of the day's highest quote in KDB?
How can I set up an Expo notification to be scheduled every day except for Saturdays and Sundays?
How can I schedule Google Colab to run at a certain time every day?
How can we create summary tables by using nested tibbles?
What could be causing new Date(`${day}/${month}/${year}`).getDay() to provide an incorrect weekday?