Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
question by a beginner
#11
Example.
import csv

with open('csv_data.csv') as csvfile:
    reader = csv.reader(csvfile, delimiter=';')
    for row in reader:
        print(','.join(row))
Output:
name, age, number Salah, 22, 1, 26/01, ali, 23, 2, 26/01, Ranard, 30, 3, 26/01
For Pandas look at this post.
Reply
#12
(Jan-27-2019, 06:58 PM)salahoum Wrote: I explained my problem but the idea did not arrive
I simply re-explain
the videos in YouTube they read the data from the csv file like:

name, age, number, and the date; Salah; 22; 1; 26/01; ali; 23; 2; 26/01; Ranard; 30; 3; 26/01

I need to display it as:

name number date
salah 22 1 1/26
ali 23 2 26/01
ranard 30 3 26/01

There are three column headers (name, number, date) but four data columns separated by tab. Is it typo? What does mean 'display'? Is there one long row or data is on separate rows?

Based on limited knowledge a would propose something along those lines:

>>> s = ['name; age; number; date',
...      'Salah; 22; 1; 26/01',
...      'ali; 23; 2; 26/01',
...      'Ranard; 30; 3; 26/01']
>>> for row in s:
...     print(*row.split(';'))
name  age  number  date
Salah  22  1  26/01
ali  23  2  26/01
Ranard  30  3  26/01
I'm not 'in'-sane. Indeed, I am so far 'out' of sane that you appear a tiny blip on the distant coast of sanity. Bucky Katt, Get Fuzzy

Da Bishop: There's a dead bishop on the landing. I don't know who keeps bringing them in here. ....but society is to blame.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  A simple "If...Else" question from a beginner Serena2022 6 1,638 Jul-11-2022, 05:59 AM
Last Post: Serena2022
Question Beginner Boolean question [Guessing game] TKB 4 2,227 Mar-22-2022, 05:34 PM
Last Post: deanhystad
  Beginner question NameError amazing_python 6 2,380 Aug-13-2021, 07:28 AM
Last Post: amazing_python
  Beginner question - storing values cybertron2 4 3,137 Mar-09-2021, 04:21 AM
Last Post: deanhystad
  beginner question about lists and functions sudonym3 5 2,666 Oct-17-2020, 12:31 AM
Last Post: perfringo
  beginner question ___ 1 1,704 Jul-12-2020, 08:12 AM
Last Post: Gribouillis
  Beginner question: lxml's findall in an xml namespace aecklers 0 2,864 Jan-22-2020, 10:53 AM
Last Post: aecklers
  Super easy beginner question AkulaLA 3 3,173 Nov-07-2019, 03:42 AM
Last Post: Larz60+
  Basic Beginner question NHeav 4 2,708 Sep-13-2019, 11:43 AM
Last Post: NHeav
  Beginner Question - Esaping the Escape Character correctly? Bramen 4 2,653 Aug-27-2019, 02:38 PM
Last Post: Bramen

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020