Using pandas in a csv modified file?

  csv, pandas, python

is it possible to use pandas after rewriting data into a csv using something like this:

import csv
headers = []

cleaned_data = open('cleaned_data.csv', 'w')
writer = csv.writer(cleaned_data)

for row in open("house_prices.csv"):
# <-- Some body code here to filter out the headers

This is where I want to continue with my cleaning of data and get rid of rows that contain missing values. I’ve been told that using pandas is the way to go but I’m not sure if it’s ok to do it since the first steps are to write this code:

import pandas as pd
df = pd.read_csv('house_prices.csv')

which conflicts with my first code, right? So is it possible to remove rows of missing values with this method or is there another way without importing anything?

Or would it be possible to combine both?ie:

import csv
import pandas as pd
headers = []

cleaned_data = open('cleaned_data.csv', 'w')
writer = csv.writer(cleaned_data)

df = pd.read_csv('house_prices.csv')
df.dropna(axis=0, how='any', thresh=None, subset=None, inplace=False)

for row in open("house_prices.csv"):
# <-- Some body code here to filter out the headers

Would that work? This is the first time I’m seeing pandas

Source: Python Questions

LEAVE A COMMENT