इनपुट -
मान लीजिए आपके पास एक DataFrame है, और पहले कॉलम को शिफ्ट करने और लापता मान भरने का परिणाम है:
one two three 0 1 10 100 1 2 20 200 2 3 30 300 enter the value 15 one two three 0 15 1 10 1 15 2 20 2 15 3 30
समाधान
इसे हल करने के लिए, हम नीचे दिए गए दृष्टिकोण का पालन करेंगे:
एक DataFrame परिभाषित करें
नीचे दिए गए कोड का उपयोग करके पहले कॉलम को शिफ्ट करें
data.shift(periods=1, axis=1)
उपयोगकर्ता से मान प्राप्त करें और सत्यापित करें कि यह 3 और 5 से विभाज्य है। यदि परिणाम सत्य है तो लापता मान भरें, अन्यथा NaN भरें
user_input = int(input("enter the value"))
if(user_input%3==0 and user_input%5==0):
print(data.shift(periods=1, axis=1, fill_value=user_input))
else:
print(data.shift(periods=1, axis=1))
उदाहरण
बेहतर समझ के लिए पूरा कार्यान्वयन देखें:
import pandas as pd
data = pd.DataFrame({'one': [1,2,3],
'two': [10,20,30],
'three': [100,200,300]})
print(data)
user_input = int(input("enter the value"))
if(user_input%3==0 and user_input%5==0):
print(data.shift(periods=1, axis=1, fill_value=user_input))
else:
print(data.shift(periods=1, axis=1))
आउटपुट 1
one two three 0 1 10 100 1 2 20 200 2 3 30 300 enter the value 15 one two three 0 15 1 10 1 15 2 20 2 15 3 30
आउटपुट 2
one two three 0 1 10 100 1 2 20 200 2 3 30 300 enter the value 3 one two three 0 NaN 1.0 10.0 1 NaN 2.0 20.0 2 NaN 3.0 30.0