Issue
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:\users\asus\appdata\local\programs\python\python39\lib\site-packages\pandas\util\_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)
Solution
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
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.