Python Forum
How to do next line output from CSV column?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to do next line output from CSV column?
#3
Not sure I understand the request, but this will get you column 4 as a comma separated string, if that is what you want.
You could write string to a csv file.
You can probably do this more elegantly using pandas.

# read straight to a dictionary
# the columns are: fname, lname, department, birthday_month
# so column 4 is birthday_month
import csv
path = '/home/pedro/myPython/csv/'
with open(path + 'employees.txt', mode='r') as csv_file:
    csv_reader = csv.DictReader(csv_file)
    name_records = list(csv_reader) # gives a list of dictionaries where the key is the column header

# here column 4 is 'birthday_month'
# get all   'birthday_month' records as a comma-separated string   
string = ''
for d in name_records:
    string = string + d['birthday_month'] + ','
    # get rid of the last comma
    string = string[0:-1]
atomxkai likes this post
Reply


Messages In This Thread
RE: How to do next line output from CSV column? - by Pedroski55 - Oct-02-2021, 01:00 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Reading and storing a line of output from pexpect child eagerissac 1 4,433 Feb-20-2024, 05:51 AM
Last Post: ayoshittu
  [Solved] Reading every nth line into a column from txt file Laplace12 7 5,408 Jun-29-2021, 09:17 AM
Last Post: Laplace12
  beginner text formatting single line to column jafrost 4 3,330 Apr-28-2021, 07:03 PM
Last Post: jafrost
  How to input & output parameters from command line argument shantanu97 1 2,652 Apr-13-2021, 02:12 PM
Last Post: Larz60+
  Add a new line to a CSV in one column bazcurtis 7 3,178 Sep-01-2020, 01:31 PM
Last Post: bazcurtis
  Jupiter Notebook does not show output line Renym 3 2,739 Apr-26-2020, 11:21 AM
Last Post: jefsummers
  [gpxpy] "Error parsing XML: not well-formed (invalid token): line 1, column 1" Winfried 5 6,850 Jan-26-2020, 01:09 AM
Last Post: Winfried
  A question about subprocess taking input from command line and returning output! Aurimas 8 5,346 May-15-2019, 04:02 PM
Last Post: Aurimas
  Writing values at a desired column in a line of text file Gupta 3 3,560 Jul-28-2017, 11:08 PM
Last Post: Larz60+
  String output displaying \n instead of new line... nicklesprout 4 26,006 Jul-28-2017, 08:01 PM
Last Post: ichabod801

Forum Jump:

User Panel Messages

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