[PYTHON] How to handle data frames

import pandas as pd
import numpy as np

Read csv file

df=pd.read_csv('〜〜〜.csv',header=None,names=('name', 'id'))

Specify the column name with names = ~ ~. header = None prevents the first line from being recognized as header.

Replace part of the data

df=df.replace('A B', 'AB')
df=df.replace('B A', 'BA')

Split the text in one column of df into two new columns

df2 = pd.concat([df, df['name'].str.split(' ', expand=True)], axis=1).drop('name', axis=1)

Extract multiple columns of df

df=df.loc[:,["Column name","Column name","Column name"]]

Combine dfs vertically

df3=pd.concat([df1, df2])

Delete duplicate lines

df=df[~df.duplicated()]

Extract rows that meet the conditions

df[df["Column name"]=="~~"]

List dataframe

df_list=df.values.tolist()

Make the list of columns array

df_list=np.array(df['Column name'])

Recommended Posts

How to handle data frames
How to handle time series data (implementation)
[Introduction to Python] How to handle JSON format data
Data cleaning How to handle missing and outliers
How to handle session in SQLAlchemy
How to read e-Stat subregion data
How to deal with imbalanced data
How to Data Augmentation with PyTorch
How to handle Japanese in Python
How to collect machine learning data
How to collect Twitter data without programming
How to handle consecutive values in MySQL
How to use "deque" for Python data
How to read problem data with paiza
How to create sample CSV data with hypothesis
[Django] How to get data by specifying SQL.
[Python] How to read data from CIFAR-10 and CIFAR-100
How to scrape horse racing data with BeautifulSoup
How to use data analysis tools for beginners
How to get article data using Qiita API
How to read time series data in PyTorch
How to search HTML data using Beautiful Soup
[Python] How to handle Japanese characters with openCV
How to handle datetime type in python sqlite3
How to use xml.etree.ElementTree
How to use Python-shell
How to use tf.data
How to use virtualenv
Scraping 2 How to scrape
How to use Seaboan
How to use image-match
How to use shogun
How to install Python
How to read PyPI
How to install pip
How to use Virtualenv
How to use numpy.vectorize
How to update easy_install
How to install archlinux
How to use pytest_report_header
How to restart gunicorn
How to virtual host
How to debug selenium
How to use partial
How to use Bio.Phylo
How to read JSON
How to use SymPy
How to use x-means
How to use WikiExtractor.py
How to update Spyder
How to install BayesOpt
How to use virtualenv
How to use Matplotlib
How to use iptables
How to use numpy
How to use TokyoTechFes2015
How to use venv
How to use Pyenv
How to use list []
How to use python-kabusapi
How to install Nbextensions