Skip to main content

Extensions of pythonnet package to support pandas DataFrame conversions

Project description

pandasnet

Build Status

license pypi python supported

pandasnet is a python package build on top of pythonnet. It provides additional data conversions for pandas, numpy and datetime

Prerequisites

  • python 3.6 or higher.
  • dotnet.

dotnet also provides scripts to proceed the installation by command line.

Installation

pip install pandasnet

Features

To load the converter you need to import the package once in your python environment. If the dotnet clr isn't started yet through the pytonnet package the import will.

import pandasnet

We construct a simple C# function to test conversion

using System;
using System.Collections.Generic;

namespace LibForTests
{
    public class PandasNet
    {
        public static Dictionary<string, Array> BasicDataFrame(Dictionary<string, Array> df)
            => df;
    }
}

We build this function into a library named LibForTests.dll. We load this library into our python environment then use it.

import clr
import pandasnet # Load the converters
import pandas as pd
from datetime import datetime

# Load your dll
clr.AddReference('LibForTests.dll')
from LibForTests import PandasNet as pdnet

x = pd.DataFrame({
    'A': [1, 2, 3],
    'B': [1.23, 1.24, 1.22],
    'C': ['foo', 'bar', 'other'],
    'D': [datetime(2021, 1, 22), datetime(2021, 1, 23), datetime(2021, 1, 24)]
})
y = pdnet.BasicDataFrame(x)

print(y)

Below an exhausitve list of supported data convertions.

Python -> .Net

Python .Net
datetime.datetime DateTime
datetime.date DateTime
datetime.timedelta TimeSpan
datetime.time TimeSpan
numpy.ndarray(dtype=bool_) bool[]
numpy.ndarray(dtype=int8) sbyte[]
numpy.ndarray(dtype=int16) short[]
numpy.ndarray(dtype=int32) int[]
numpy.ndarray(dtype=int64) long[]
numpy.ndarray(dtype=uint8) byte[]
numpy.ndarray(dtype=uint16) ushort[]
numpy.ndarray(dtype=uint32) uint[]
numpy.ndarray(dtype=uint64) ulong[]
numpy.ndarray(dtype=float32) float[]
numpy.ndarray(dtype=float64) double[]
numpy.ndarray(dtype=datetime64) DateTime[]
numpy.ndarray(dtype=timedelta64) TimeSpan[]
numpy.ndarray(dtype=str) string[]
pandas._libs.tslibs.timestamps.Timestamp DateTime
pandas._libs.tslibs.timedeltas.TimeDelta TimeSpan
pandas.core.series.Series Array
pandas.core.frame.DataFrame Dictionary[string, Array]

.Net -> Python

.Net Python
DateTime datetime.datetime
TimeSpan datetime.timedelta
bool[] numpy.ndarray(dtype=bool_)
sbyte[] numpy.ndarray(dtype=int8)
short[] numpy.ndarray(dtype=int16)
int[] numpy.ndarray(dtype=int32)
long[] numpy.ndarray(dtype=int64)
byte[] numpy.ndarray(dtype=uint8)
ushort[] numpy.ndarray(dtype=uint16)
uint[] numpy.ndarray(dtype=uint32)
ulong[] numpy.ndarray(dtype=uint64)
float[] numpy.ndarray(dtype=float32)
double[] numpy.ndarray(dtype=float64)
DateTime[] numpy.ndarray(dtype=datetime64)
TimeSpan[] numpy.ndarray(dtype=timedelta64)
Dictionary[string, Array] pandas.core.frame.DataFrame

Contributing

Issue tracker: https://github.com/fdieulle/pandasnet/issues

If you want to checkout the project and propose your own contribution, you will need to setup it following few steps:

Create a virtual environment:

python -m venv venv

Activate your virtual environment:

venv/Scripts/activate

Install package dependencies

pip install -r requirements.txt

License

This project is open source under the MIT license.

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

pandasnet-0.4.tar.gz (15.2 kB view details)

Uploaded Source

Built Distribution

pandasnet-0.4-py3-none-any.whl (29.9 kB view details)

Uploaded Python 3

File details

Details for the file pandasnet-0.4.tar.gz.

File metadata

  • Download URL: pandasnet-0.4.tar.gz
  • Upload date:
  • Size: 15.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.3.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.0 CPython/3.8.7

File hashes

Hashes for pandasnet-0.4.tar.gz
Algorithm Hash digest
SHA256 a7b16f2cc8adcc6328c23551e85bbf0ba51942dc1dcfef3fb65d4cd5970d7edb
MD5 a67fde3494a5b57187e13f75fc8d0c7a
BLAKE2b-256 0f20429b3779d6634e3f50fbd6f3eaf45f398c7e7ec5a446a08be26f7876a440

See more details on using hashes here.

File details

Details for the file pandasnet-0.4-py3-none-any.whl.

File metadata

  • Download URL: pandasnet-0.4-py3-none-any.whl
  • Upload date:
  • Size: 29.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.3.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.0 CPython/3.8.7

File hashes

Hashes for pandasnet-0.4-py3-none-any.whl
Algorithm Hash digest
SHA256 4374f92e3de006eaaa8b6274b8e4807b71dfecde816d898a3dbc7eb18ecbe106
MD5 9f575dfcbd3f5ba05f14aa45f7ec8d97
BLAKE2b-256 775a793e95b2f0da7912182173137d11f09b868dfcaffce9af7ee6ad92a9bbd5

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page