0

My current csv file :

'Date','Category','Ability'
'21,2,5','Sparrow','Air,land'
'4,5,6','Eagle','Air,Land'

Header is Date,category ,Ability....If i print the Date,then my expected output is [21,2,5,4,5,6]...but i get ['21,2,5','4,5,6']......

My code :

Date_val=[]
with open(Filepath,'r') as f :
 user_read=Dictreader(f)
 for row in user_read:
   Date_val=Date_val..append(row['Date'])
print(Date_val)

I really what i wanna do is if a date has today date,then i need to read that values seperately.... for eg my csv file has

'Date','Category','Ability' '21,14,5','Sparrow','Air,land' '4,5,6','Eagle','Air,Land' '21,14,5','Penguin','water,land'

then print(Category_Exp) is [Sparrow,Penguin] print(Ability) is [Air,land,water,land]

1 Answers1

0

When reading your csv using pandas, it automatically assumes your csv columns are seperated by commmas. If your column names have commas in them like in your case, pandas thinks that is a column. So either change your column names to not have a comma in it, or specify your seperator in pandas before reading it in. Hope it helps

Bearishcat
  • 25
  • 4
  • 1
    OP is not using pandas though. In fact pandas could easily handle OP's file because the fields are already quoted: `pd.read_csv(filename, quotechar="'")` – tdy Feb 03 '23 at 03:39