python memorandum super basic

How to write import-free syntax

#generate list
list = [0,1,2]
print(list)

[0, 1, 2]

#Add list

list2 = [[0,1,2]]
list2.append([3,4,5])
list2

[[0, 1, 2], [3, 4, 5]]

#list

len([0,1,2])

3

#list

[0,1,2].count(0)

1

#dictionary{key:value}Created in the format of
#Returns value when specified in method get

{"Miyasako" : "Honest", "Tamura" : "return"}.get("Miyasako")

'Shinshin'

#list specified in slice
#[:3]Specify from 0 to the third before

[0, 1, 2, 3, 4, 5][:3]

[0,1,2]

#How to make a UDF function

def printHello():
    return print("Hello, world!!")
 
printHello()

'Hello, world!!'

#Conditional branch in if statement

x = 10
if x <= 20:
    print("x is 20 or less.")
 
if x <= 30:
    print("x is 30 or less.")
 
elif x >=40:
    print("x is 40 or more.") #This sentence does not appear

'x is 20 or less. ' 'x is 30 or less. '

#for statement

x = 0
for i in range(100):
    x += i

4950

numpy module import

#Import numpy module
import numpy as np
example1 = np.array([2, 4, 6, 8, 10])
example1

array([ 2, 4, 6, 8, 10])

#print("{}".format())Can be commented so it is easy to check the contents

print("example1:\n{}".format(example1))

example1: [ 2 4 6 8 10]

#If you pass a nested list

example2 = np.array([[1, 2, 3, 4, 5], [2, 4, 6, 8, 10]])
example2

array( [[ 1, 2, 3, 4, 5], [ 2, 4, 6, 8, 10]])

#Dimension and shape of example2
#Note that shape cannot be used for list! Let's put it in ndarray

print(example2.ndim, example2.shape)

2 (2, 5)

#Matrix permutation

example2.transpose()

array( [[ 1, 2], [ 2, 4], [ 3, 6], [ 4, 8], [ 5, 10]])

#ndarray → list conversion

np.array([1,2,3,4,5][2,3,4,5,6]).tolist()

pandas module import

#Import pandas module
import pandas as pd
data = pd.DataFrame({"area" : [18, 19, 20], "age" : [5, 4, 10]}, index = ["A", "B", "C"])
data

image.png

#Refer to only the first n lines of the data frame.
data.head(1)

image.png

#Numpy array of values from the dataframe/Get a numpy array of column names.
data.values, data.columns

(array([ [ 5, 18], [ 4, 19], [10, 20]]), Index(['age', 'area'], dtype='object'))

#Summary statistics
data.describe()

image.png

#Correlation coefficient
data.corr()

image.png

#Delete column
data = data.drop("time", axis = 1)
data

image.png

#Column selection
data[["age","area"]]

image.png

#Condition specification
data[(data["age"]<=5) & (data["area"]==18)]

image.png

# ndarray→dataframe

A = np.array([[1,2],[2,3],[3,4]])
 
#cloumns naming
B = pd.DataFrame(A,columns={"NO_1","NO_2"})
  
#columns renamed
B.rename(columns={"NO_1":"no1","NO_2":"no2"})

image.png image.png

#Aggregate
B.groupby("NO_1",as_index=False).sum()

image.png

Recommended Posts

python memorandum super basic
Python basic memorandum part 2
Python memorandum
Python Memorandum 2
Python memorandum
python memorandum
python memorandum
Python memorandum
python memorandum
Python memorandum
Python basics memorandum
RF Python Basic_01
Python memorandum (algorithm)
Basic Python writing
Python3 basic grammar
Python memorandum [links]
RF Python Basic_02
Python basic course (12 functions)
Python I'm also basic
Python memorandum numbering variables
Python basic grammar / algorithm
Python Basic Course (7 Dictionary)
Python basic course (2 Python installation)
Basic sorting in Python
python memorandum (sequential update)
[Python] Super useful debugging
Python basic course (9 iterations)
[python] class basic methods
Python Basic Course (11 exceptions)
Linux basic command memorandum
Python memorandum (personal bookmark)
Python basic course (6 sets)
Python3 cheat sheet (basic)
Python basic grammar (miscellaneous)
Python Basic Course (Introduction)
python basic on windows ②
Python basic memo --Part 2
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
[Python] Iterative processing_Personal memorandum
OpenCV basic code (python)
Memorandum @ Python OR Seminar
Python basic memo --Part 1
Python basic course (8 branches)
Python basic if statement
Python Basic Course (3 Python Execution)
Python Basic --Pandas, Numpy-
Effective Python Learning Memorandum Day 15 [15/100]
Basic Python 3 grammar (some Python iterations)
Cisco Memorandum _ Python config input
Super basic usage of pytest
Refactoring Learned in Python (Basic)
python super beginner tries scraping
Effective Python Learning Memorandum Day 6 [6/100]
BASIC authentication with Python bottle
Effective Python Learning Memorandum Day 12 [12/100]
Python basic dict sort order