[PYTHON] Get one column from DataFrame with DataFrame

The title has become difficult to understand, but it is the same article. Sweat

In conclusion, In access by brackets (square brackets) ** If there is only one bracket, it can be retrieved as a Series, and if the brackets are stacked, it can be retrieved as a DataFrame. ** **

#Can be taken with Series
df["col"] # df.Same for col

#Can be taken with DataFrame
df[["col"]]

It is possible to convert what was taken out by Series to DataFrame, but it is easy to stack brackets.

If you specify multiple columns and get it, it is essential to overlap the brackets, so you can always get it with DataFrame.

df[["col1", "col2", "col3"]] #Can be taken with DataFrame

In addition, as a case where it is inconvenient to get it in Series, there is a case where it is input to the prediction model of sklearn. When creating a model with one variable, the following error will be output by inputting with Series.

ValueError: Expected 2D array, got 1D array instead:
~~
Reshape your data either using array.reshape(-1, 1) ~~

that's all.

Recommended Posts

Get one column from DataFrame with DataFrame
Get Redmine User list with DataFrame
Get html from element with Python selenium
[Note] Get data from PostgreSQL with Python
Get data from Cloudant with Bluemix flask
Replace column names / values with pandas dataframe
Get data from an oscilloscope with pyVISA
[Python] Get one year's message history from Slack
Get schedule from Garoon SOAP API with Python + Zeep
Get started with MicroPython
Get Tweets with Tweepy
Get mail from Gmail and label it with Python3
Get date with python
Get started with Mezzanine
Python hand play (get column names from CSV file)
Get data from database via ODBC with Python (Access)
Get the package version to register with PyPI from Git
Get data from analytics API with Google API Client for python
Get message from first offset with kafka consumer in python
Get Japanese stock price information from yahoo finance with pandas
Convert DataFrame column names from Japanese to English using Googletrans
Get structural data from CHEMBLID
Get country code with python
Get table dynamically with sqlalchemy
Get started with Django! ~ Tutorial ⑤ ~
Get Twitter timeline with python
Get started with influxDB + Grafana
Get Youtube data with python
Get information with zabbix api
Get started with Django! ~ Tutorial ④ ~
Insert from pd.DataFrame with psycopg2
Get clipboard from Maya settings
Get started with Django! ~ Tutorial ⑥ ~
Rename column names with django-south
Get thread ID with python
Get started with Python! ~ ② Grammar ~
Get image features with OpenCV
Get stock price with Python
Get home directory with python
Get keyboard events with python
With skype, notify with skype from python!
Get Alembic information with Python
Get another tab with pyppeteer
Get ranking with Rakuten API
Get PowerShell commands from malware dynamic analysis site with BeautifulSoup + Python
python / pandas / dataframe / How to get the simplest row / column / index / column
Get data from MySQL on a VPS with Python 3 and SQLAlchemy
Get US stock price from Python with Web API with Raspberry Pi
Get OCTA simulation conditions from a file and save with pandas