'can not plot a graph using matplotlib showing error

Exception has occurred: ImportError dlopen(/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/PIL/_imaging.cpython-39-darwin.so, 0x0002): symbol not found in flat namespace '_xcb_connect' File "/Users/showrov/Desktop/Machine learning/Preprosessing/import_dataset.py", line 2, in <module> import matplotlib.pyplot as plt

import matplotlib.pyplot as plt

import pandas as pd

import numpy as np

import sys

print(sys.version)

data=pd.read_csv('Data_customer.csv')

print(data)

plt.plot(data[:2],data[:2])



Solution 1:[1]

data[:2] will return the first 2 rows. In order to plot, you need to use the columns. Mention the column name directly like data['columnName'] otherwise use the iloc method. for example: data.iloc[:, 1:2] in order to access 2nd column. For more information about indexing operations, please check out below link https://pandas.pydata.org/docs/user_guide/indexing.html

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Jagruti Shinde