Pandas basics for beginners ① Reading & processing

What is pandas

A data frame object for handling structured data in Python. You can easily read files and perform subsequent SQL operations, and it is necessary for work such as machine learning to process, calculate, and visualize data. A memo list of commonly used syntaxes for data manipulation. This section is data reading & processing.

Library import

Import pandas with the name pd

python


import pandas as pd

Read file

python


dataflame = pd.read_csv('file.csv')

Excel etc. can be read by the same method. Official Pandas documentation [Input / output]

Data confirmation

Enter the required number in parentheses.

python


dataflame.head(10)

The display from the beginning is "head", and the display from the end is "tail".

Create column

Add the existing "column1" and "column2" to make "column3".

python


dataflame['column3'] = dataflame['column1'] + dataflame['column2']

Join

"Left Outer Join" with "dataflame1" and "dataflame2" in the column "key", and make it "join_dataflame".

python


join_dataflame = pd.merge(dataflame1, dataflame2, on = 'key', how = 'left')

If you want to limit the columns, add dataflame1 [['column1','column1']].

Data dump

Dump the data with csv.

python


dataflame.to_csv('dump_file.csv', index = false, encoding = 'utf-8', sep=",")

"Index" specifies the presence or absence of a header, "encoding" specifies the encoding, and "sep" specifies the delimiter.

Check the number of data

Check the number of "dataflame".

python


print(len(dataflame))

Recommended Posts

Pandas basics for beginners ① Reading & processing
Pandas basics for beginners ⑧ Digit processing
Pandas basics summary link for beginners
Basics of pandas for beginners ② Understanding data overview
Seaborn basics for beginners ④ pairplot
100 Pandas knocks for Python beginners
Seaborn basics for beginners ② Histogram (distplot)
Pandas basics
[Must-see for beginners] Basics of Linux
Pandas basics
Pandas basics for beginners ④ Handling of date and time items
Processing memos often used in pandas (beginners)
Roadmap for beginners
Python Pandas is not suitable for batch processing
[Pandas] Basics of processing date data using dt
100 language processing knock-20 (using pandas): reading JSON data
[For recording] Pandas memorandum
Spacemacs settings (for beginners)
Python basics ② for statement
Processing datasets with pandas (1)
Processing datasets with pandas (2)
Summary of pre-processing practices for Python beginners (Pandas dataframe)
MongoDB Basics: Transaction Processing
Reading pandas format file
python textbook for beginners
100 Language Processing Knock: Chapter 2 UNIX Command Basics (using pandas)
[Introduction for beginners] Reading and writing Python CSV files
100 language processing knock-30 (using pandas): reading morphological analysis results
[Linux] Basics of authority setting by chmod for beginners
Dijkstra algorithm for beginners
OpenCV for Python beginners
Seaborn basics for beginners ③ Scatter plot (jointplot) * With histogram
[For beginners] Basics of Python explained by Java Gold Part 2
[Explanation for beginners] Introduction to convolution processing (explained in TensorFlow)
[Explanation for beginners] Introduction to pooling processing (explained in TensorFlow)
[For beginners] Basics of Python explained by Java Gold Part 1
Learning flow for Python beginners
[For beginners] kaggle exercise (merucari)
Linux distribution recommended for beginners
CNN (1) for image classification (for beginners)
Python3 environment construction (for beginners)
Overview of Docker (for beginners)
Python #function 2 for super beginners
Basic Python grammar for beginners
Python for super beginners Python #functions 1
Python #list for super beginners
~ Tips for beginners to Python ③ ~
[For Kaggle beginners] Titanic (LightGBM)
Reference resource summary (for beginners)
Linux command memorandum [for beginners]
Data processing tips with Pandas
Convenient Linux shortcuts (for beginners)
[Python] Iterative processing (for, while)
[Pandas] I tried to analyze sales data with Python [For beginners]
Seaborn basics for beginners ① Aggregate graph of the number of data (Countplot)