Created
November 26, 2021 16:19
-
-
Save AhmadMoussa/bdf07b0193673db40e4ca34a86507160 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pandas as pd | |
file_path = 'path_to_your.csv' | |
if(file_path[-4:] == '.csv'): | |
df = pd.read_csv(file_path, sep=';') | |
df.to_excel (file_path[:-4] + '.xlsx', index = None, header=True) | |
file_path = file_path[:-4] + '.xlsx' | |
sheet = pd.read_excel(file_path, sheet_name='Sheet1') | |
#print(len(sheet)) | |
sheet = sheet[sheet['Operation'] == 'transaction'] | |
sheet = sheet.drop(['Received EUR', 'From address', 'Sent EUR', 'Fee XTZ', 'Fee EUR', 'To address', 'Explorer link', 'Block level', 'Operation'], axis=1) | |
sheet = sheet.fillna('') | |
import math | |
def applyFunc(s): | |
if s != '': | |
return 'XTZ' | |
else: | |
return '' | |
def applyFunc2(s): | |
if s != '': | |
return 0 | |
else: | |
return '' | |
def applyFunc3(s): | |
if s != '': | |
return abs(float(s.replace(',','.'))) | |
else: | |
return '' | |
sheet["Received Currency"] = "" | |
sheet['Received Currency'] = sheet['Received XTZ'].apply(applyFunc) | |
sheet['Received XTZ'] = sheet['Received XTZ'].apply(applyFunc3) | |
sheet["Sent Currency"] = "" | |
sheet['Sent Currency'] = sheet['Sent XTZ'].apply(applyFunc) | |
sheet["Fee Amount"] = sheet['Sent XTZ'].apply(applyFunc2) | |
sheet["Fee Currency"] = sheet['Fee Amount'].apply(applyFunc) | |
sheet["Tag"] = "" | |
sheet['Sent XTZ'] = sheet['Sent XTZ'].apply(applyFunc3) | |
sheet = sheet.rename(columns={'Datetime': 'Date', 'Received XTZ': 'Received Quantity', 'Sent XTZ': 'Sent Quantity'}) | |
sheet = sheet[['Date', 'Received Quantity', 'Received Currency', 'Sent Quantity', 'Sent Currency', 'Fee Amount', 'Fee Currency', 'Tag']] | |
sheet = sheet[sheet['Sent Quantity'] != 0.0] | |
sheet = sheet[(sheet['Received Quantity'] != '') | (sheet['Sent Quantity'] != '')] | |
#print(sheet.columns) | |
#print(sheet) | |
#print(len(sheet)) | |
sheet.to_csv('cointracker.csv', index=False) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment