Jun-04-2019, 06:46 PM
Situation:
Learning Pandas, using Nederlands OV CHipkaart data (mine) for a month to test pandas and practice
Currently can read the file into a dataframe.
I'm still learning so working through this step by step.
Just as I get to understand I lose or forget how.
Problem:
I cannot seem to get the two dataframes to merge.
Can you suggest a way, or several ways to do this better?
or point to a reference to do this better?
Learning Pandas, using Nederlands OV CHipkaart data (mine) for a month to test pandas and practice
Currently can read the file into a dataframe.
Quote:Date, Check-in, Departure, Check-out, Destination, Amount, Transaction, Class, Product, Comments, Name, Card numberI am splitting the data into two dataframes, one for checking in, one for checking out.
Quote:Date, Time, Departure, TypeMy code...
Date, Time, Destination, Cost, Type
import os import re import datetime as dt import numpy import pandas as pd data = None try: df = pd.read_csv('privatefiles/t.csv',';') #df = pd.read_csv('...','\t') #xlsx = Excel_File('t.xlsx') #df = pd.read_excel(xlsx,0) #print(df.head(3)) #print(len(df)) except Exception as err: print('Problem with reading the file.<br/> '+err) checkin = df[df['Transaction']=='Check-in'].rename(columns={'Check-in':'Time'}) checkin = checkin[['Date','Time','Departure']].reset_index() checkout = df[df['Transaction']=='Check-out'] checkout = checkout[['Date','Check-out','Destination','Amount']].rename(columns={'Check-out':'Time','Amount':'Cost'}).reset_index() #checkout['Type','Departure','Duration']=['Check-out','',0.] cleaned = pd.DataFrame(columns=['Type','Date','Time','Departure','Destination','Cost','Duration','IsWork']) cleaned += checkinComplexity:
I'm still learning so working through this step by step.
Just as I get to understand I lose or forget how.
Problem:
I cannot seem to get the two dataframes to merge.
Can you suggest a way, or several ways to do this better?
or point to a reference to do this better?