Question
hello , MY program showing indentation error , could you please verify my code and let m,e know where i am wrong . import pandas
hello ,
MY program showing indentation error , could you please verify my code and let m,e know where i am wrong .
import pandas as pd
import numpy as np
import datetime
def transform(df):
def fix_zip(input_zip):
try:
input_zip = int(float(input_zip))
except:
try:
input_zip = int(input_zip.split('-')[0])
except:
return np.NaN
if input_zip < 10000 or input_zip > 19999:
return np.NaN
return str(input_zip)
df = pd.read_csv('311_data.csv')
df['Incident Zip'] = df['Incident Zip'].apply(fix_zip)
df = df.dropna(how='any',inplace=True)
df = df[df['Borough'] != 'Unspecified']
df['Created Date'] = df['Created Date'].apply(lambda x:datetime.datetime.strptime(x,'%m/%d/%Y %I:%M:%S %p'))
df['Closed Date'] = df['Closed Date'].apply(lambda x:datetime.datetime.strptime(x,'%m/%d/%Y %I:%M:%S %p'))
df['processing_time'] =df['Closed Date'] - df['Created Date']
df = df[df['processing_time']>=datetime.timedelta(0,0,0)]
return df.to_csv('output1.csv')
transform()
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started