Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

select series of columns

# Import pandas package
import pandas as pd
  
# Define a dictionary containing employee data
data = {'Name':['Jai', 'Princi', 'Gaurav', 'Anuj'],
        'Age':[27, 24, 22, 32],
        'Address':['Delhi', 'Kanpur', 'Allahabad', 'Kannauj'],
        'Qualification':['Msc', 'MA', 'MCA', 'Phd']}
  
# Convert the dictionary into DataFrame 
df = pd.DataFrame(data)
  
# select all rows 
# and second to fourth column
df[df.columns[1:4]]
Comment

select series of columns

# Import pandas package
import pandas as pd
  
# Define a dictionary containing employee data
data = {'Name':['Jai', 'Princi', 'Gaurav', 'Anuj'],
        'Age':[27, 24, 22, 32],
        'Address':['Delhi', 'Kanpur', 'Allahabad', 'Kannauj'],
        'Qualification':['Msc', 'MA', 'MCA', 'Phd']}
  
# Convert the dictionary into DataFrame 
df = pd.DataFrame(data)
  
# iloc[row slicing, column slicing]
df.iloc [0:2, 1:3]
Comment

select series of columns

# Import pandas package
import pandas as pd
  
# Define a dictionary containing employee data
data = {'Name':['Jai', 'Princi', 'Gaurav', 'Anuj'],
        'Age':[27, 24, 22, 32],
        'Address':['Delhi', 'Kanpur', 'Allahabad', 'Kannauj'],
        'Qualification':['Msc', 'MA', 'MCA', 'Phd']}
  
# Convert the dictionary into DataFrame 
df = pd.DataFrame(data)
  
# Remember that Python does not
# slice inclusive of the ending index.
# select all rows 
# select first two column
df.iloc[:, 0:2]
Comment

select series of columns

# Import pandas package
import pandas as pd
  
# Define a dictionary containing employee data
data = {'Name':['Jai', 'Princi', 'Gaurav', 'Anuj'],
        'Age':[27, 24, 22, 32],
        'Address':['Delhi', 'Kanpur', 'Allahabad', 'Kannauj'],
        'Qualification':['Msc', 'MA', 'MCA', 'Phd']}
  
# Convert the dictionary into DataFrame 
df = pd.DataFrame(data)
  
# select two rows and 
# column "name" to "Address"
# Means total three columns
df.loc[0:1, 'Name':'Address']
Comment

PREVIOUS NEXT
Code Example
Python :: back of list 
Python :: plot bar chart python with resulting numbers 
Python :: how to make a relationship in python 
Python :: list the contents of a package python 
Python :: Python - Cómo cruda la cuerda 
Python :: oop - Apa metaclasses di Python 
Python :: turtule code for digital clock 
Python :: flash not defined python flask 
Python :: merge_sort 
Python :: how to start a working to run a particular queue 
Python :: youtube view bot python code pastebin 
Python :: def identity_block(X, f, filters, training=True, initializer=random_uniform): 
Python :: how to convert a axis label to non scientific notation in matploltlib 
Python :: Create tiff stack in python 
Python :: how to export schema in graphene django 
Python :: violin plot seaborn 
Python :: tuple with only one element in Python 
Python :: binarizer pyspark 
Python :: get the value of qpushbutton pyqt5 with argument 
Python :: omr sheet python stackoverflow 
Python :: improt kmean 
Python :: naiveDateTime last week from current time 
Python :: uneven chunks of array slices 
Python :: candle stick with volume plotly 
Python :: relation api profile does not exist django 
Python :: len range 
Python :: Extract all bounding boxes using OpenCV Python 
Python :: python structure like c 
Python :: split() method, sep=i, n=veces aplicado 
Python :: nested dict 
ADD CONTENT
Topic
Content
Source link
Name
3+5 =