0

When I did it using an online tutorial, it kept telling me that there was an error with quotations, but after editing, I still don't see the problem. CAn you please help?

import csv
with open("CSV_birthdays.txt") as csv_file:
    csv_converter = csv.reader(csv_file, delimiter=',') # This suggests that commas seperate classes
    linenum = 0
    for row in csv_converter:
        if linenum == 0:
            print("There are 4 family members I have dealt with so far")
            linenum +=1 # go to the next line
        else: # for the actual columns printing out my sentences
            print(f"\t{row[0]} is {row[1]} years old, and they were born on the {row[2]}th) of {row[3]}{row[4]}.")
            linenum += 1 # print the next line
    print(f"I have the birthdays of {linenum} people")

This is the csv file I'm referring to

name, age, birthday ,birthday month, birth year
me, 15, 17, March, 2005
my sister, 13 , 1 , 8, 3006
Manson, 10, 22, 11, 2009
Fred, 15, 7, 6, 2004

CobraCoder
  • 35
  • 8

2 Answers2

0

Change the the file name to "CSV_birthdays.csv"

Then use pandas

import pandas as pd

df = pd.read_csv("CSV_birthdays.csv")
df.head()
df.tail()
df.info()
df.describe()
Mo Huss
  • 434
  • 2
  • 11
0

Thank you. I may not have understood what pandas is, but you have helped me to understand my errors.

import csv
with open("birthday.txt") as csv_file:
    csv_converter = csv.reader(csv_file, delimiter=',') # This suggests that commas seperate classes
    linenum = 0
    for row in csv_converter:
        if linenum == 0:
            print("There are 4 family members I have dealt with so far")
            linenum +=1 # go to the next line
        else: # for the actual columns printing out my sentences
            name = ''.join(row[0])
            age = ''.join(row[1])
            birthday =''.join(row[2])
            birthmonth =''.join(row[3])
            birthyear = ''.join(row[4])

            print (name +" is" + age +" years old, and they were born on the " + birthday + "of " + birthmonth + "" + birthyear +".")
            linenum += 1 # print the next line
        print("\there is the original format")
        print ','.join(row)
CobraCoder
  • 35
  • 8