मान लें कि हमारी CSV फ़ाइल की सामग्री निम्नलिखित हैं -
Car Reg_Price 0 BMW 2000 1 Lexus 1500 2 Audi 1500 3 Jaguar 2000 4 Mustang 1500
आवश्यक पुस्तकालयों को आयात करें -
import pandas as pd import matplotlib.pyplot as mp
हमारी सीएसवी फाइल डेस्कटॉप पर है। CSV फ़ाइल से डेटा को पंडों के डेटाफ़्रेम में लोड करें -
d = pd.read_csv("C:\\Users\\amit_\\Desktop\\SalesData.csv")
dataFrame = pd.DataFrame(d.head(), columns=["Car","Reg_Price"]) डेटाफ़्रेम प्लॉट करें -
dataFrame.plot(x="Car", y="Reg_Price", kind="bar", figsize=(10, 9))
उदाहरण
निम्नलिखित कोड है -
import pandas as pd
import matplotlib.pyplot as mp
# read csv
d = pd.read_csv("C:\\Users\\amit_\\Desktop\\SalesData.csv")
print("\nReading the CSV file...\n",d)
# dataframe
dataFrame = pd.DataFrame(d.head(), columns=["Car","Reg_Price"])
# plotting the dataframe
dataFrame.plot(x="Car", y="Reg_Price", kind="bar", figsize=(10, 9))
# displaying bar graph
mp.show() आउटपुट
यह निम्न आउटपुट प्रदर्शित करेगा -
