Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

first column of a dataframe python

import pandas as pd
# List of Tuples
empoyees = [('Jack',    34, 'Sydney',   5) ,
            ('Riti',    31, 'Delhi' ,   7) ,
            ('Aadi',    16, 'London',   11) ,
            ('Mark',    41, 'Delhi' ,   12)]
# Create a DataFrame object
df = pd.DataFrame(  empoyees, 
                    columns=['Name', 'Age', 'City', 'Experience'])
print("Contents of the Dataframe : ")
print(df)
# Select first column of the dataframe as a dataframe object
first_column = df.iloc[: , :1]
print("First Column Of Dataframe: ")
print(first_column)
print("Type: " , type(first_column))
# Select first column of the dataframe as a series
first_column = df.iloc[:, 0]
print("First Column Of Dataframe: ")
print(first_column)
print("Type: " , type(first_column))
Source by www.kite.com #
 
PREVIOUS NEXT
Tagged: #column #dataframe #python
ADD COMMENT
Topic
Name
9+9 =