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 dict to url params 
Python :: square finder python 
Python :: python tkinter listbox click event 
Python :: python read xml 
Python :: skip header in csv python 
Python :: remove item from list while looping 
Python :: python blackjack 
Python :: pad zeros to a string python 
Python :: Make tkinter window look less blury 
Python :: python requests header 
Python :: Square of numbers in non-decreasing order 
Python :: django override help text 
Python :: print every element in list python outside string 
Python :: DateTime object representing DateTime in Python 
Python :: python list contains substring 
Python :: plotly express lineplot 
Python :: virtual env in mac 
Python :: python parse dict from string 
Python :: python blueprint 
Python :: truncate date to midnight in pandas column 
Python :: python index where true 
Python :: firefox selenium python 
Python :: how to save inputs python 
Python :: python last element in list 
Python :: count how many vowels in a string python 
Python :: python strftime microseconds 
Python :: python sqlalchemy engine 
Python :: how to open html file in python 
Python :: only int validator PyQt 
Python :: user input dictionary python 
ADD CONTENT
Topic
Content
Source link
Name
4+7 =