Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

how to create a subset of two columns in a dataframe

In [2]: titanic = pd.read_csv("data/titanic.csv")

In [3]: titanic.head()
Out[3]: 
   PassengerId  Survived  Pclass                                               Name     Sex   Age  SibSp  Parch            Ticket     Fare Cabin Embarked
0            1         0       3                            Braund, Mr. Owen Harris    male  22.0      1      0         A/5 21171   7.2500   NaN        S
1            2         1       1  Cumings, Mrs. John Bradley (Florence Briggs Th...  female  38.0      1      0          PC 17599  71.2833   C85        C
2            3         1       3                             Heikkinen, Miss. Laina  female  26.0      0      0  STON/O2. 3101282   7.9250   NaN        S
3            4         1       1       Futrelle, Mrs. Jacques Heath (Lily May Peel)  female  35.0      1      0            113803  53.1000  C123        S
4            5         0       3                           Allen, Mr. William Henry    male  35.0      0      0            373450   8.0500   NaN        S
age_sex = titanic[["Age", "Sex"]] <--- this is the sliced Data Frame which is created by
defining a list of the desired columns to be sliced
Comment

PREVIOUS NEXT
Code Example
Python :: 2nd to last index python 
Python :: guessing game python 
Python :: django make app 
Python :: dataframe column condition in list 
Python :: python test module 
Python :: windows instalar python 
Python :: open multiple plots python 
Python :: matplotlib remove drawn text 
Python :: how to register a model in django 
Python :: how to write a function in python 
Python :: change column order pandas 
Python :: binary search tree in python 
Python :: delete content of table django 
Python :: Removing Elements from Python Dictionary Using clear() method 
Python :: how to pass multiple parameters by 1 arguments in python 
Python :: Convert csv to dictionary in Python 
Python :: double for in loop python 
Python :: list count python 
Python :: python list with several same values 
Python :: pyqt5 hide button 
Python :: docstring in python 
Python :: how to close opened file in python 
Python :: push button raspberry pi 
Python :: python escape forward slash 
Python :: how to make loops in python 
Python :: Python DateTime Date Class Syntax 
Python :: check if a value is in index pandas dataframe 
Python :: python interview questions and answers pdf 
Python :: longest palindromic substring using dp 
Python :: geodataframe get crs 
ADD CONTENT
Topic
Content
Source link
Name
1+6 =