A Pandas extension to make work with Jalali Date easier.
Project description
Jalali Pandas Extentsion
A pandas extension that solves all problems of Jalai/Iraninan/Shamsi dates
Features
Series Extenstion
- Convert string to Jalali date
1388/03/25
-->jdatetime(1388,3,25,0,0)
- Convert Georgian date to Jalali date
datetime(2019,11,17,0,0)
-->jdatetime(1398,8,26,0,0)
- Convert Jalali date to Georgian date
jdatetime(1398,10,18,0,0)
-->datetim(2020,1,8,6,19)
DataFrame extenstion
- Support grouping by Jalali date
- Group by year, month, days, ...
- Shortcuts for groups:
ymd
for['year','month','day']
and more - Resampling: Convenience method for frequency conversion and resampling of time series but in Jalali dateformat. (comming soon)
Installation
pip install -U jalali-pandas
Usage
Just import jalali-pandas and use pandas just use .jalali
as a method for series and dataframes. Nothin outside pandas.
jalali-pandas
is an extentsion for pandas, that add a mehtod for series/columns and dataframes.
Series
import pandas as pd
import jalali_pandas
# create dataframe
df = pd.DataFrame({"date": pd.date_range("2019-01-01", periods=10, freq="D")})
# convert to jalali
df["jdate"] = df["date"].jalali.to_jalali()
# convert to gregorian
df["gdate"] = df["jdate"].jalali.to_georgian()
# parse string to jalali
df1 = pd.DataFrame({"date": ["1399/08/02", "1399/08/03", "1399/08/04"]})
df1["jdate"] = df1["date"].jalali.parse_jalali("%Y/%m/%d")
# get access to jalali year,quarter ,month, day and weekday
df['year'] = df["jdate"].jalali.year
df['month'] = df["jdate"].jalali.month
df['quarter'] = df["jdate"].jalali.quarter
df['day'] = df["jdate"].jalali.day
df['weekday'] = df["jdate"].jalali.weekday
DataFrame
import pandas as pd
import jalali_pandas
df = pd.DataFrame(
{
"date": pd.date_range("2019-01-01", periods=10, freq="M"),
"value": range(10),
}
)
# make sure to create a column with jalali datetime format. (you can use any name)
df["jdate"] = df["date"].jalali.to_jalali()
# group by jalali year
gp = df.jalali.groupby("year")
gp.sum()
#group by month
mean = df.jalali.groupby('mean')
#groupby year and month and day
mean = df.jalali.groupby('ymd')
# or
mean = df.jalali.groupby(['year','month','day'])
#groupby year and quarter
mean = df.jalali.groupby('yq')
# or
mean = df.jalali.groupby(['year','quarter'])
ToDos:
- add Georgian to Jalali Conversion
- add Jalali to Georgian Conversion
- add support for sampling
- add date parser from other columns
- add date parser from string
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
jalali_pandas-0.1.2.tar.gz
(16.4 kB
view details)
Built Distribution
File details
Details for the file jalali_pandas-0.1.2.tar.gz
.
File metadata
- Download URL: jalali_pandas-0.1.2.tar.gz
- Upload date:
- Size: 16.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.1.11 CPython/3.8.9 Darwin/21.1.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | b7e6c31003032c1f45b3eb1892499a8966eef6eccf7331a18e88f014b1928726 |
|
MD5 | ba60b838b5a483c5dadf6621562225fa |
|
BLAKE2b-256 | c19e3caaa2f66957e4c099117e6cb0eacdde6bdfc4bc748f12b29ffffe2e71e3 |
File details
Details for the file jalali_pandas-0.1.2-py3-none-any.whl
.
File metadata
- Download URL: jalali_pandas-0.1.2-py3-none-any.whl
- Upload date:
- Size: 16.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.1.11 CPython/3.8.9 Darwin/21.1.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | d6b3984910ce2b8aca312a8651079106b38eeb40b0958b824b663162b5c9124b |
|
MD5 | d886e3b781121feb1fd4caa1397b7a3d |
|
BLAKE2b-256 | 46928be802cb3b185a37a2b9a641fea2f1356d579ef0872febe90a87b21567e9 |