why can't run cell "tweet_df = load_data()"

Question:

import pandas as pd
import numpy as np
import nltk
import string
import re

def load_data():
    data = pd.read_csv('tweet.csv')
    return data

tweet_df = load_data()

I want to load "twitter.csv" data, which contains the crawled results of 1000 tweet data.
but error and generate code like the following

ParserError                               Traceback (most recent call last)
Input In [6], in <module>
----> 1 tweet_df = load_data()

Input In [2], in load_data()
      1 def load_data():
----> 2     data = pd.read_csv('tweet.csv')
      3     return data

File c:usersasusappdatalocalprogramspythonpython39libsite-packagespandasutil_decorators.py:311, in deprecate_nonkeyword_arguments.<locals>.decorate.<locals>.wrapper(*args, **kwargs)
    305 if len(args) > num_allow_args:
    306     warnings.warn(
    307         msg.format(arguments=arguments),
    308         FutureWarning,
    309         stacklevel=stacklevel,
    310     )
--> 311 return func(*args, **kwargs)
Asked By: Raffi El

||

Answers:

The twitter data is semi-colon separated so you need to provide delimiter or sep argument

def load_data(file_name, delim):
    data = pd.read_csv(file_name,delimiter=delim)
    return data

tweet_df = load_data('twitter.csv',delim=';')

the pandas can infer delimiter if you use engine='python' argument in the read_csv refer documentation the argument sep https://pandas.pydata.org/docs/reference/api/pandas.read_csv.html

Answered By: Deepan

Are you using up to date pandas package?

Try pip3 install --upgrade pandas

Assuming you use pip to manage packages.

Answered By: magouda
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.