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

3
  • Can you also share the exception? Commented Apr 28, 2020 at 9:37
  • can you please explain what you mean by that? Commented Apr 28, 2020 at 9:53
  • sorry. i saw this on the internet and thought that this may be neccessary Commented Apr 28, 2020 at 10:15

2 Answers 2

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()
Sign up to request clarification or add additional context in comments.

2 Comments

What is pandas?
Pandas is the go to library for working with data in python. first you need to install it. pandas.pydata.org you can use pip to install it or conda
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)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.