i am here
Screen_Shot_2018-12-28_at_6_47_38_PM.png
i want to merge all rowsof 3 rd col so that output looks like...

end result should be....
Screen_Shot_2018-12-28_at_6_49_34_PM.png

Dani AI

Generated

The screenshots show a desire to concatenate every value from the 3rd CSV column into one string (third column = index 2 with 0-based indexing). 's suggestion to try pandas is a good starting point because it handles quoting, delimiters and encodings reliably. Below are two practical approaches: a concise pandas solution and a memory-friendly pure-Python (csv) alternative.

Pandas (simple):

import pandas as pd

df = pd.read_csv('input.csv')           # set sep='\t' or other if not comma
col = df.iloc[:, 2].dropna().astype(str)
merged = col.str.cat(sep=' ')           # change sep to ',' or '\n' if desired
print(merged)

Pandas (large files, streaming):

parts = []
for chunk in pd.read_csv('input.csv', usecols=[2], header=None, chunksize=100000):
    parts.append(chunk.iloc[:,0].dropna().astype(str).str.cat(sep=' '))
merged = ' '.join(parts)

Pure-Python (csv, streaming to avoid high memory):

import csv

with open('input.csv', newline='', encoding='utf-8') as f, open('merged.txt', 'w', encoding='utf-8') as out:
    reader = csv.reader(f)
    # skip header if present: next(reader)
    first = True
    for row in reader:
        if len(row) >= 3 and row[2].strip():
            if not first:
                out.write(' ')
            out.write(row[2])
            first = False

Notes and troubleshooting: confirm whether the file has a header (skip it), confirm the delimiter (comma vs tab), and handle encoding (utf-8 vs others). If fields contain commas or embedded newlines, rely on pandas or the csv module rather than manual splitting. For deduplication while preserving order, use an OrderedDict or a simple seen set with list append. These snippets complement 's point and give both the quick pandas route and a low-memory fallback for very large CSVs.

Recommended Answers

All 2 Replies

its not solved yet please help

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.