Python application: Pandas Part 1: Basic

I will post about pandas from today.

What is Pandas

A library for databases in python.

In particular A library for handling sets of data like NumPy. NumPy can treat data as a mathematical matrix and specializes in scientific calculations.

Pandas, on the other hand, can perform operations that can be done with common databases. In addition to numerical values, you can easily handle character string data such as name and address.

Data analysis can be performed efficiently by using NumPy and Pandas properly.

Two types of data structures

There are two types of data structures in Pandas: Series and DataFrame.

DataFrame It is a data structure that is mainly used and is represented by a two-dimensional table. Horizontal data is called a row, and vertical data is called a column.

Each row and each column is labeled Row label is index Column labels are called columns.

Series It is a one-dimensional array that can be thought of as a row or column in a DataFrame. Again, each element is labeled.

Data structure example

image.png

The index is [0, 1, 2, 3, 4]. Also, the columns are ["Prefecture", "Area", "Population", "Region"].

Checking Series and DataFrame data

Series is dictionary type data ({key1: value1, key2: value2, ...}) By passing, it will be sorted in ascending order by key.

#Series data

import pandas as pd

fruits = {"orange": 2, "banana": 3}
print(pd.Series(fruits))
#Output result
banana    3
orange    2
dtype: int64
#Similarly, DataFrame is sorted by key in ascending order if columns are not specified.
#Data in DataFrame

import pandas as pd

data = {"fruits": ["apple", "orange", "banana", "strawberry", "kiwifruit"],
        "year": [2001, 2002, 2001, 2008, 2006],
        "time": [1, 4, 5, 6, 3]}
df = pd.DataFrame(data)
print(df)
#Output result
       fruits  time  year
0       apple     1  2001
1      orange     4  2002
2      banana     5  2001
3  strawberry     6  2008
4   kiwifruit     3  2006
#To specify the sort order, use columns as the second argument as shown below.=[list]To specify.

import pandas as pd
df = pd.DataFrame(data, columns=["year", "time", "fruits"])
print(df)
#Output result
   year  time      fruits
0  2001     1       apple
1  2002     4      orange
2  2001     5      banana
3  2008     6  strawberry
4  2006     3   kiwifruit

Recommended Posts

Python application: Pandas Part 1: Basic
Python application: Pandas Part 2: Series
Python application: data visualization part 1: basic
Python application: Pandas Part 4: DataFrame concatenation / combination
Python basic memorandum part 2
Python basic memo --Part 2
Python basic memo --Part 1
Python application: Pandas # 3: Dataframe
Python Basic --Pandas, Numpy-
Python Basic Grammar Memo (Part 1)
Python Application: Data Cleansing Part 1: Python Notation
Python Application: Data Handling Part 3: Data Format
Python application: Numpy Part 3: Double array
1. Statistics learned with Python 1-1. Basic statistics (Pandas)
Excel aggregation with Python pandas Part 1
QGIS + Python Part 2
RF Python Basic_01
My pandas (python)
Python Application: Data Visualization Part 3: Various Graphs
QGIS + Python Part 1
Basic Python writing
Excel aggregation with Python pandas Part 2 Variadic
Python: Scraping Part 1
Python3 basic grammar
Python Basic Memorandum Part 3-About Object Orientation-
RF Python Basic_02
python pandas notes
Python3 Beginning Part 1
Python: Scraping Part 2
pandas series part 1
(Note) Basic statistics on Python & Pandas on IBM DSX
Python Application: Data Handling Part 2: Parsing Various Data Formats
Basic operation of Python Pandas Series and Dataframe (1)
Python basic course (12 functions)
Python I'm also basic
Python basic grammar / algorithm
Python Basic Course (7 Dictionary)
Python basic course (2 Python installation)
Basic sorting in Python
Python basic course (9 iterations)
Basic operation of pandas
[python] class basic methods
Python Basic Course (11 exceptions)
Python basic course (6 sets)
Basic operation of Pandas
Python3 cheat sheet (basic)
Python basic grammar (miscellaneous)
Python Basic Course (Introduction)
Installing pandas on python2.6
python basic on windows ②
Python basic course (13 classes)
Basic Python command memo
Python basic grammar note (4)
Python basic grammar note (3)
Basic knowledge of Python
Python basic grammar memo
OpenCV basic code (python)
Application of Python 3 vars
python memorandum super basic
Python basic course (8 branches)
Python basic if statement