কলাম ভ্যালুগুলোর কাউন্ট গণনা করতে, count() মেথড ব্যবহার করুন। প্রথমে পান্ডাস লাইব্রেরি ইম্পোর্ট করুন:
import pandas as pd
দুটি কলাম সহ একটি ডেটাফ্রেম তৈরি করুন:
dataFrame1 = pd.DataFrame({
"Car": ['BMW', 'Lexus', 'Audi', 'Tesla', 'Bentley', 'Jaguar'],
"Units": [100, 150, 110, 80, 110, 90]})
count() ফাংশন ব্যবহার করে "Units" কলামের ভ্যালুগুলোর কাউন্ট খুঁজুন:
print("Count of values of Units column from DataFrame1 = ", dataFrame1['Units'].count())
উसी तरह, আমরা ২য় ডেটাফ্রেম থেকে কাউন্ট গণনা করেছি।
উদাহরণ
নিচে সম্পূর্ণ কোড দেওয়া হলো:
import pandas as pd
# Create DataFrame1
dataFrame1 = pd.DataFrame({
"Car": ['BMW', 'Lexus', 'Audi', 'Tesla', 'Bentley', 'Jaguar'],
"Units": [100, 150, 110, 80, 110, 90]})
print("DataFrame1 ...\n", dataFrame1)
# Finding count of values of a specific column
print("Count of values of Units column from DataFrame1 = ", dataFrame1['Units'].count())
# Create DataFrame2
dataFrame2 = pd.DataFrame({
"Product": ['TV', 'PenDrive', 'HeadPhone', 'EarPhone', 'HDD'],
"Price": [8000, 500, 3000, 1500, 3000]})
print("\nDataFrame2 ...\n", dataFrame2)
# Finding count of values of all the column
print("\nCount of column values from DataFrame2 = \n", dataFrame2.count())
আউটপুট
এটি নিচের আউটপুট তৈরি করবে:
DataFrame1 ... Car Units 0 BMW 100 1 Lexus 150 2 Audi 110 3 Tesla 80 4 Bentley 110 5 Jaguar 90 Count of values of Units column from DataFrame1 = 6 DataFrame2 ... Price Product 0 8000 TV 1 500 PenDrive 2 3000 HeadPhone 3 1500 EarPhone 4 3000 HDD Count of column values from DataFrame2 = Price 5 Product 5 dtype: int64