3.Write a Python program to import data from Comma Separated Files (CSV) file, clean data, and export data in CSV file.

import csv
with open('Student_scores.csv', 'w', newline='') as file:
    writer = csv.writer(file)
    writer.writerow(["Name", "Score 1", "Score 2"])
    writer.writerow(["Alex",62,80])
    writer.writerow(["Brad",45,56])
    writer.writerow(["Joey",85,98])
   
import csv
with open('Student_scores.csv', 'r',) as file:
    reader = csv.reader(file, delimiter = '\t')
    for row in reader:
      print(row)
     
import pandas as pd
# Importing and viewing the first 5 rows

dframe = pd.read_csv("insurance.csv")
dframe.head()

# Importing and viewing the first 5 rows

dframe = pd.read_table('insurance.csv', sep=',')
dframe.head()

dframe.duplicated()

dframe.drop_duplicates()

dframe.fillna(0)

dframe.dropna()

dframe.to_csv("dframe.csv", sep='?')

Post a Comment

0 Comments