Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

fancy index python

import numpy as np
import pandas as pd
m = np.random.randint(1,30, size = (10,3))
df = pd.DataFrame(m, columns = ["var1", "var2", "var3"])

	var1	var2	var3
0	9		9		25
1	29		9		7
2	24		27		25
3	24		29		14
4	1		1		11
5	12		12		26
6	7		24		20
7	15		8		15
8	6		19		9
9	15		28		12

df[0:2][["var1","var3"]] ## pay attention to the second square brackets
output:
  var1	var3
0	9	25
1	29	7
Comment

PREVIOUS NEXT
Code Example
Python :: Regular Expressions In Practical NLP example 
Python :: python property class 
Python :: Python Printing negative timedelta object 
Python :: adding new character in string python 
Python :: python read and write lines in file 
Python :: plotly two y axis bar chart grouped 
Python :: Errors that you will get during date object in python datetime 
Python :: scraped text in Russian encoding python 
Python :: latex new command with arguments 
Python :: line of best fit in linear regression 
Python :: django save object 
Python :: deoplete 
Python :: parsing date columns when reading csv 
Python :: convert depth image to point cloud 
Python :: how to open local software using python 
Python :: decorrelation of data using PCA 
Python :: Extract columns of dataframe to make new dataframe 
Python :: python tk highlightthicknes 
Python :: pandas to_csv overwrite check 
Python :: pyaudio get system audio 
Python :: TypeError: strptime() argument 1 must be str, not list 
Python :: Combine first and last 3 columns into new dataframe 
Python :: Pandas: Ternary conditional operator for setting a value in a DataFrame 
Python :: python pyhue 
Python :: tkinter radiobutton "bind_all" 
Python :: how to get foregine key field from models 
Python :: gui apps 
Python :: python output parameter 
Python :: django datepicker mindate and maxdate 
Python :: pandas typr of each cell in series 
ADD CONTENT
Topic
Content
Source link
Name
7+2 =