Q. Given a DataFrame df:-

       Name Sex    Position       City  Age  Projects  Budget
0     Rabia   F     Manager  Bangalore   30        13      48
1      Evan   M  Programmer  New Delhi   27        17      13
2       Jia   F     Manager    Chennai   32        16      32
3      alit   M     Manager     Mumbai   40        20      21
4  Jaspreet   M  Programmer    Chennai   28        21      17
5      Suji   F  Programmer  Bangalore   32        14      10

Write a program to print only the Name, Age and Position for all rows.


Answer :-

import pandas as pd
import numpy as np

x = { 'Name': ['Rabia', 'Evan', 'Jia', 'alit', 'Jaspreet', 'Suji'],
          'Sex': ['F', 'M', 'F', 'M', 'M', 'F'],
          'Position': ['Manager', 'Programmer', 'Manager', 'Manager',
                       'Programmer', 'Programmer'],\
          'City': ['Bangalore', 'New Delhi', 'Chennai', 'Mumbai',
                   'Chennai', 'Bangalore'],
          'Age': [30, 27, 32, 40, 28, 32],
          'Projects': [13, 17, 16, 20, 21, 14],
          'Budget': [48, 13, 32, 21, 17, 10]}

df = pd.DataFrame (x)

for i, row in df.iterrows():
    print (row['Name'], '\t', row['Age'], '\t', row['Position'])


Output :-

 Rabia      30      Manager
Evan      27      Programmer
Jia      32      Manager
alit      40      Manager
Jaspreet      28      Programmer
Suji      32      Programmer

>>>

Post a Comment

You can help us by Clicking on ads. ^_^
Please do not send spam comment : )

Previous Post Next Post