Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

python - subset specific columns name in a dataframe

columns = ['b', 'c']
df1 = pd.DataFrame(df, columns=columns)
Comment

Selecting subset of columns with pandas

import pandas as pd

data = pd.read_excel (r'C:UsersRonDesktopProduct List.xlsx') 
df = pd.DataFrame(data, columns= ['Product'])
print (df)
Comment

Selecting subset of columns with pandas

import pandas as pd

data = pd.read_excel (r'C:UsersRonDesktopProduct List.xlsx') 
df = pd.DataFrame(data, columns= ['Product'])
print (df)
Comment

Selecting subset of columns with pandas

import pandas as pd

data = pd.read_excel (r'C:UsersRonDesktopProduct List.xlsx') 
df = pd.DataFrame(data, columns= ['Product'])
print (df)
Comment

Selecting subset of columns with pandas

import pandas as pd

data = pd.read_excel (r'C:UsersRonDesktopProduct List.xlsx') 
df = pd.DataFrame(data, columns= ['Product'])
print (df)
Comment

select subset of columns from dataframe

In [25]: titanic.iloc[9:25, 2:5]
Out[25]: 
    Pclass                                 Name     Sex
9        2  Nasser, Mrs. Nicholas (Adele Achem)  female
10       3      Sandstrom, Miss. Marguerite Rut  female
11       1             Bonnell, Miss. Elizabeth  female
12       3       Saundercock, Mr. William Henry    male
13       3          Andersson, Mr. Anders Johan    male
..     ...                                  ...     ...
20       2                 Fynney, Mr. Joseph J    male
21       2                Beesley, Mr. Lawrence    male
22       3          McGowan, Miss. Anna "Annie"  female
23       1         Sloper, Mr. William Thompson    male
24       3        Palsson, Miss. Torborg Danira  female

[16 rows x 3 columns]
Comment

pandas dataframe subset of columns

age_sex = titanic[["Age", "Sex"]]

In [9]: age_sex.head()
Out[9]: 
    Age     Sex
0  22.0    male
1  38.0  female
2  26.0  female
3  35.0  female
4  35.0    male
Comment

PREVIOUS NEXT
Code Example
Python :: python requests no certificate example 
Python :: python start process in background and get pid 
Python :: win64pyinstaller 
Python :: lambda en python 
Python :: python dropbox 
Python :: iterate a list of tuples 
Python :: get html input in django 
Python :: ValueError: query data dimension must match training data dimension 
Python :: python turn off garbage collection 
Python :: data where values in column starts with particular value 
Python :: python set workdir 
Python :: python find string count in str 
Python :: max of a list python 
Python :: how to click a div element in selenium python 
Python :: how to not create a new line in python 
Python :: input two numbers in python in a single line 
Python :: python replace n with actual new line 
Python :: get binary string python 
Python :: python string remove whitespace 
Python :: how to use for loop to take n number of input in python 
Python :: register template tag django 
Python :: calculate quartil python 
Python :: df sort by column names 
Python :: django trim string whitespace 
Python :: open file dialog on button click pyqt5 
Python :: python input list of ints 
Python :: sns boxplot 
Python :: python multiply 2 variables 
Python :: mount gdrive in pyton 
Python :: python convert strings to chunks 
ADD CONTENT
Topic
Content
Source link
Name
1+6 =