লিডিং বা ট্রেইলিং হোয়াইটস্পেস রিমুভ করতে strip() মেথড ব্যবহার করুন। প্রথমে ৩টি কলাম "Product Category", "Product Name" এবং "Quantity" সহ একটি DataFrame তৈরি করুন:
dataFrame = pd.DataFrame({
'Product Category': [' Computer', ' Mobile Phone', 'Electronics ', 'Appliances', ' Furniture', 'Stationery'],
'Product Name': ['Keyboard', 'Charger', ' SmartTV', 'Refrigerators', ' Chairs', 'Diaries'],
'Quantity': [10, 50, 10, 20, 25, 50]})
একাধিক কলাম থেকে হোয়াইটস্পেস রিমুভ করুন:
dataFrame['Product Category'].str.strip() dataFrame['Product Name'].str.strip()
উদাহরণ
সম্পূর্ণ কোড নিচে দেওয়া হলো:
import pandas as pd
# ৩টি কলাম সহ dataframe তৈরি
dataFrame = pd.DataFrame({
'Product Category': [' Computer', ' Mobile Phone', 'Electronics ', 'Appliances', ' Furniture', 'Stationery'],
'Product Name': ['Keyboard', 'Charger', ' SmartTV', 'Refrigerators', ' Chairs', 'Diaries'],
'Quantity': [10, 50, 10, 20, 25, 50]})
# ১-től অধিক কলাম থেকে হোয়াইটস্পেস রিমুভ
dataFrame['Product Category'].str.strip()
dataFrame['Product Name'].str.strip()
# dataframe
print("Dataframe after removing whitespaces...\n", dataFrame)
আউটপুট
Dataframe after removing whitespaces... Product Category Product Name Quantity 0 Computer Keyboard 10 1 Mobile Phone Charger 50 2 Electronics SmartTV 10 3 Appliances Refrigerators 20 4 Furniture Chairs 25 5 Stationery Diaries 50