0

""" I am trying to plot a graph from data retrieved from a CSV file. The code is as below """

path = '/Users/pradeepallath/Documents/000_Edureka_Training/001_PredictiveAnalysis/Weather_WWII'
import pandas as pd
dataset = pd.read_csv(path+'/Weather.csv',low_memory=False,nrows=1000)
dataset.plot(x='MinTemp',y='MaxTemp',style=0)
plt.plot()

"""
I am Getting this error. Please note I am new to Python

        Traceback (most recent call last):
          File "/Users/pradeepallath/Documents/Pycharm/Big_Mart_Sale/Mean_Sale.py", line 13, in <module>
            dataset.plot(x='MinTemp',y='MaxTemp',style=0)
          File "/Users/pradeepallath/anaconda3/lib/python3.7/site-packages/pandas/plotting/_core.py", line 794, in __call__
            return plot_backend.plot(data, kind=kind, **kwargs)
          File "/Users/pradeepallath/anaconda3/lib/python3.7/site-packages/pandas/plotting/_matplotlib/__init__.py", line 62, in plot
            plot_obj.generate()
          File "/Users/pradeepallath/anaconda3/lib/python3.7/site-packages/pandas/plotting/_matplotlib/core.py", line 281, in generate
            self._make_plot()
          File "/Users/pradeepallath/anaconda3/lib/python3.7/site-packages/pandas/plotting/_matplotlib/core.py", line 1063, in _make_plot
            style, kwds = self._apply_style_colors(colors, kwds, i, label)
          File "/Users/pradeepallath/anaconda3/lib/python3.7/site-packages/pandas/plotting/_matplotlib/core.py", line 723, in _apply_style_colors
            nocolor_style = style is None or re.match("[a-z]+", style) is None
          File "/Users/pradeepallath/anaconda3/lib/python3.7/re.py", line 173, in match
            return _compile(pattern, flags).match(string)
        TypeError: expected string or bytes-like object

    Thanks for the assistance

"""

4
  • May be change the columns data type using astype(str), check this link pandas.pydata.org/pandas-docs/stable/reference/api/… Commented Nov 27, 2019 at 4:59
  • No it did not work, tried converting using the following command. dataset.astype({'MinTemp':'int32'},).dtypes dataset.astype({'MaxTemp':'int32'}).dtypes Commented Nov 27, 2019 at 5:20
  • Check what types it is first. dataset.dtypes should give that information. Commented Nov 27, 2019 at 5:22
  • Load the CVS into a DataFrame first, then check the dtype property of the columns to isolate the error. Pandas has a bad habit of switching data types behind your back. Avoiding chaining a load and operation in the same cell (if you're in jupyter lab/notebook), or both in the same command within an interpreter will help you out, too. Commented Nov 27, 2019 at 5:28

1 Answer 1

1

It's taking issue with style=0. Pandas supports matplotlib line styles. Here is a good stackoverflow question on how you can see valid options, but essentially the integer zero is not a valid line style.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.