Cleaning Stripe csv
  • AI Chat
  • Code
  • Report
  • Beta
    Spinner
    # Start coding here... 
    import pandas as pd
    
    x="Itemized_balance_change_from_activity_USD_2024-04-16_to_2024-04-30_UTC.csv"
    y='Itemized_payouts_USD_2024-04-16_to_2024-04-30_UTC.csv'
    
    text = pd.read_csv(x, index_col='balance_transaction_id')
    textpayout = pd.read_csv(y, index_col='balance_transaction_id')
    
    #incoming transactions processing
    text.created = text.created.str[:10]
    
    text.fee = -1 * text.fee
    
    text = text.drop('available_on', axis=1)
    text = text.drop('net', axis=1)
    text2 = text.copy()
    
    text2.gross = text2.fee
    text2.reporting_category = "fee"
    
    text = text.drop('fee', axis=1)
    text2 = text2.drop('fee', axis=1)
    
    #payout transactions processing
    
    textpayout.effective_at = textpayout.effective_at.str[:10]
    textpayout.description = "transfer to bank account"
    textpayout = textpayout.rename(columns={'effective_at':'created'})
    textpayout.gross = -1 * textpayout.gross
    
    text3 = textpayout[['created', 'currency', 'gross', 'reporting_category', 'description']]
    
    #forming the final file
    text = pd.concat([text, text2, text3])
    #text = pd.concat([text, text2])
    print(text.describe)
    
    text4 = text.loc[text.gross != 0]
    print(text4.describe)
    
    text4.to_csv('statement.csv')