1
import random
import string
import csv
from ntropy_sdk import SDK, Transaction
from io import StringIO
import pandas as pd

transactions = """description   amount  iso_currency_code
Aktywna Warszawa   S    21.07   PLN
Crv*Ww Beauty Lukasz Mich   18.83   PLN
Bolt.Eu/R/2207180715    96.34   EUR
Purchase from AMZN  3.64    EUR
## DEPOSIT  95.77   EUR
CARD TRANSACTION #69420 74.05   EUR
>> ^0_o^ << 64.97   EUR
Crypto.com: Allegro.pl gift card purchase   74.7    EUR
Paypal help ukraine donate  68.76   EUR
OPENPAY*CERVEZASIEMPRE CIUDAD DE MEXIC  26.47   USD
PAYPAL INST XFER MICROSOFT ACH_DEBIT    4.9 USD
Paypal *xsolla mtgarena 70.35   USD
M10GRAPHIC   CA venture capital call    27.71   USD
Compra Cart Elo Estacao Imperial Ltd    52.88   USD
PIERRE CARD IN  79.28   USD
twitch blizzard overwatch Mr Streamer   45.76   USD
Dep Transf Bdn Maria Jose Resende   46.07   USD
AMZN Mktp US AWS    85.94   USD
LATE FEE FOR PAYMENT DUE transbank  86.89   USD
ntropy api pmnt 1.84    USD"""

def df_from_csv(transactions=None): 
    csv = StringIO() 
    csv.seek(0)  
    df = pd.read_csv(csv, sep='\t')
    txs = [] 

    account_name = generate_random_string() #smjesti funk generate random string u objekt account name

    for i, row in df.iterrows():
        tx = {
            "date": "2022-01-01",
            "entry_type": "outgoing",
            "amount": row['amount'],
            "iso_currency_code": row["iso_currency_code"],
            "description": row["description"],
            "transaction_id": f"id_{i}_{generate_random_string()}",
            "account_holder_type": "consumer",
            "account_holder_id": account_name,
        }
        txs.append(tx)

    return pd.DataFrame(txs)

...

So, ath the end , I get :EmptyDataError: No columns to parse from file

What im i doing wrong? I was expecting to get result with transactions in rows as object, or

HedgeHog
  • 22,146
  • 4
  • 14
  • 36
biGmazi
  • 11
  • 3

1 Answers1

0

There is the content / string of transactions missing, so change:

def df_from_csv(transactions=None): 
    csv = StringIO()

to:

def df_from_csv(transactions=None): 
    csv = StringIO(transactions)
HedgeHog
  • 22,146
  • 4
  • 14
  • 36
  • Thank you @HedgeHog for your time and answer. Unfortunately adding : csv = StringIO(transactions) did not solve the problem, I get message: /usr/local/lib/python3.7/dist-packages/pandas/_libs/parsers.pyx in pandas._libs.parsers.TextReader.__cinit__() EmptyDataError: No columns to parse from file – biGmazi Oct 30 '22 at 11:54