I have a csv file several columns. I simplify it in the following case with two.
ID texto
1 Los niños comen sardinas
2 Los pájaros vuelan alto porque tienen alas
3 Érase una vez la vida
4 Un 67% de los adultos vive en la pobreza
I want to print only the "text" column. And I do not get it. I have tried a thousand ways:
import pandas as pd
fields = ['ID', 'texto']
df = pd.read_csv('Libro1.csv', usecols=fields)
# See the keys
print (df.keys())
# See content in 'ID' y 'texto'
print (df.texto)
Error:
raise ValueError("Usecols do not match names.")
ValueError: Usecols do not match names.
Other:
import csv
from collections import defaultdict
columns = defaultdict(list) # each value in each column is appended to a list
with open('Libro1.csv') as csvfile:
reader = csv.DictReader(csvfile) # read rows into a dictionary format
for row in reader: # read a row as {column1: value1, column2: value2,...}
for (k,v) in row.items(): # go over each column name and value
columns[k].append(v) # append the value into the appropriate list
# based on column name k
print(columns[0])
None of this methods extracts me