Python Forum
question by a beginner - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: question by a beginner (/thread-15373.html)

Pages: 1 2


RE: question by a beginner - snippsat - Jan-28-2019

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.


RE: question by a beginner - perfringo - Jan-28-2019

(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