python / pandas / dataframe / How to get the simplest row / column / index / column

DataFrame creation

** ▼ Code **

df = pd.DataFrame([
    ['a0','b0','c0'],
    ['a1','b1','c1'],
    ['a2','b2','c2'],
    ['a3','b3','c3'],
], 
    columns=['a','b','c'],
    index=[0,1,2,3]
)
df

** ▼ Output result ** image.png

Get row / column specification

** ▼ Code **

#Case using loc
df.loc[[0,2],['a','c']]
#Case using iloc
df.iloc[[0,2],[0,2]]

** ▼ Output result ** image.png

Get index, column

Get index

** ▼ Code **

df.index

** ▼ Output result ** image.png

Get column

** ▼ Code **

df.columns

** ▼ Output result ** image.png

Recommended Posts

python / pandas / dataframe / How to get the simplest row / column / index / column
How to get a specific column name and index name in pandas DataFrame
How to get the Python version
How to reassign index in pandas dataframe
How to get the files in the [Python] folder
How to get the variable name itself in python
How to get the number of digits in Python
[Introduction to Python] How to get the index of data with a for statement
How to get the last (last) value in a list in Python
How to get into the python development environment with Vagrant
How to set the extended iso8601 format date to the Dataframe index
[Introduction to Python] How to get data with the listdir function
[Python] How to use Pandas Series
How to get started with Python
[Python] How to import the library
How to get followers and followers from python using the Mastodon API
[Python] How to add rows and columns to a table (pandas DataFrame)
[Python] How to get the first and last days of the month
How to find the memory address of a Pandas dataframe value
[Python] Summary of how to use pandas
How to get a stacktrace in python
[Pandas] Expand the character string to DataFrame
How to get colored output to the console
[Python] Add total rows to Pandas DataFrame
How to get the date and time difference in seconds with python
[Python] How to use the enumerate function (extract the index number and element)
How to sort by specifying a column in the Python Numpy array.
How to use the C library in Python
[Python] How to change the date format (display format)
[Python] How to read excel file with pandas
[python] Create table from pandas DataFrame to postgres
[Python] Sort the table by sort_values (pandas DataFrame)
[Algorithm x Python] How to use the list
How to erase the characters output by Python
How to get dictionary type elements of Python 2.7
How to get started with the 2020 Python project (windows wsl and mac standardization)
python I don't know how to get the printer name that I usually use.
Note: How to get the last day of the month with python (added the first day of the month)
How to get a list of files in the same directory with python
[Python] How to run Jupyter-notebook + pandas + multiprocessing (Pool) [pandas] Memo
[Python] How to remove duplicate values from the list
How to retrieve the nth largest value in Python
Think about how to program Python on the iPad
How to install Python
[Introduction to Python] How to iterate with the range function?
Check if the expected column exists in Pandas DataFrame
How to know the current directory in Python in Blender
[Reintroduction to python] How to import via the parent directory
How to use the Raspberry Pi relay module Python
[Python] How to specify the download location with youtube-dl
How to install python
[Python] How to use the graph creation library Altair
How to convert JSON file to CSV file with Python Pandas
[Python] How to deal with pandas read_html read error
[Introduction to Udemy Python3 + Application] 27. How to use the dictionary
I tried to summarize how to use pandas in python
How to get mouse wheel verdict with Python curses
[Introduction to Udemy Python3 + Application] 30. How to use the set
[Python] Summary of how to specify the color of the figure
How to use the model learned in Lobe in Python
[Introduction to Python] How to stop the loop using break?