Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import pandas as pd
- import numpy as np
- datafilepath="/tmp/data.csv"
- colnames="tstamp, spend, budget, impression"
- #A date parsing function to feed to read_csv
- #Expects string in the format YYYY-MM-dd HH:MM:SS TZ
- #Though it doesnt return a timezone aware datetime
- def dateparser(datestr):
- dt = datetime.datetime.strptime(datestr,'%Y-%m-%d %H:%M:%S %Z')
- return dt
- #Dataframe read_csv
- df = pd.read_csv(datafilepath, names=colnames, header=0,date_parser=dateparser, parse_dates=['tstamp'])
- df.head()
- #Add a column with no values
- df['new_column'] = np.nan
- #Append all data from one data frame to other
- df.append(anotherDataFrame)
- #Check and return all rows with boolean for blank columns
- #checks if the column 'spend' is null
- df[pd.isnull(df['spend']) == True]
- #Iterate on rows of dataframe
- for index, row in df.iterrows():
- print "[rownum=%s] Time: %s " % (index, row('tstamp'))
- #Drop a column
- df = df.drop(['spend', axis=1)
Add Comment
Please, Sign In to add comment