I have a csv file, 'description' which has the first column describing different attributes. I want to tell Python to just copy the first two words from each line. And then save the first two words in a new csv. I looked into the below link but could not get the result I was expecting.
How to get the first word in the string
import pandas as pd
import csv
with open('C:/Users/description.csv','r') as k:
reader = csv.reader(f, delimiter=',')
for row in reader:
print(" ".join(row.split(0)[:2]))
Error:
print(" ".join(row.split(0)[:2]))
AttributeError: 'list' object has no attribute 'split'
with open('thematchingresults.csv', 'w') as f:
df.to_csv(f)