Reputation: 901
I got an error :
ValueError: Usecols do not match columns, columns expected but not found: ['Search Query']
No matter what the column name is, it still didn't work.
Here is my code :
if __name__ == '__main__':
count = 0
conn = MongoClient()
db = conn.dbTweetsTA
twit = []
data_query = []
collectionList = []
dataB = pd.read_csv('listQuery.csv', usecols=['Search Query'])
query_list = dataB['Search Query'].tolist()
dataB.info()
print(dataB)
Here is my csv :
Printed csv :
The separator is \t
, probably that is the problem, but how do I get the column name only ?
Upvotes: 2
Views: 7092
Reputation: 25239
your separator is \t
which is 2 chars. read_csv
interprets it as regex. You need escape the \
and specify raw string. It will use python
engine on regex, so just specify it to avoid warning
dataB = pd.read_csv('listQuery.csv', sep=r'\\t',
usecols=['Search Query'], engine='python')
Upvotes: 2