I didn't know the basics of Python

I will write down what I did not know, which is the basics of Python, in the order I knew it.

Function arguments star and doublestar

Function as an argument Add \ * (star) to make a tuple type argument Add \ ** (double star) to make dictionary type argument Example)

def print_text(*x):
    print(x)

def print_text(**x):
    print(x)

Negative OR operator (for example, when deleting duplicate lines with df)

df = df[~df.duplicated()]

Add element to list

#Either one is ok
list1.extend(list2)
list1 = list1 + list2

#But this is an error
list1 = list1.extend(list2)


map I use this quite often

###For example, when making a list like for###

def plus_one(i):
    return i+1

list1 = [1,2,3]
  #Since the return value of map is an iterator, enclose it in list
list2 = list(map(puls_one,list1))
    #list2 = [2,3,4]

#You can use a lambda expression
#lambda.ver
list2 = list(map(lambda x : x+1,list1))

When processing or adding to a column with a data frame for index, item in df.iterrows() It takes a lot of time to turn it with (even if you avoid the generation of Series or take some measures).

Instead, once list = list(map(func,index_list)) Make a list of the columns you want to dig in with, and later df.assign(new_low = list) Is much faster.

I think so from the experience of running with 40 million lines of df (laughs)

Recommended Posts

I didn't know the basics of Python
How much do you know the basics of Python?
Review of the basics of Python (FizzBuzz)
About the basics list of Python basics
Learn the basics of Python ① Beginners
Basics of Python ①
Basics of python ①
I didn't know how to use the [python] for statement
I want to know the features of Python and pip
[Python3] Understand the basics of Beautiful Soup
Summary of numpy functions I didn't know
The basics of running NoxPlayer in Python
The Python project template I think of.
[Python3] Understand the basics of file operations
[Super basics of Python] I learned the basics of the basics, so I summarized it briefly.
# 4 [python] Basics of functions
Basics of python: Output
Try the free version of Progate [Python I]
I touched some of the new features of Python 3.8 ①
[Trainer's Recipe] I touched the flame of the Python framework.
Towards the retirement of Python2
About the ease of Python
Let's break down the basics of TensorFlow Python code
I checked out the versions of Blender and Python
python: Basics of using scikit-learn ①
I want to fully understand the basics of Bokeh
About the features of Python
Basics of Python × GIS (Part 1)
I downloaded the python source
The Power of Pandas: Python
I tried to summarize the string operations of Python
[Example of Python improvement] I learned the basics of Python on a free site in 2 weeks.
I tried "gamma correction" of the image with Python + OpenCV
I just changed the sample source of Python a little.
I wrote the basic grammar of Python with Jupyter Lab
I evaluated the strategy of stock system trading with Python.
[Python] I tried to visualize the follow relationship of Twitter
[Python] I tried collecting data using the API of wikipedia
What beginners learned from the basics of variables in python
I want to know the legend of the IT technology world
Basics of Python x GIS (Part 3)
Paiza Python Primer 5: Basics of Dictionaries
The story of Python and the story of NaN
[Python] The stumbling block of import
First Python 3 ~ The beginning of repetition ~
I investigated the mechanism of flask-login!
pyenv-change the python version of virtualenv
Getting Started with Python Basics of Python
Change the Python version of Homebrew
[Python] Understanding the potential_field_planning of Python Robotics
I liked the tweet with python. ..
Basics of Python x GIS (Part 2)
I wrote the queue in Python
I wrote the stack in Python
I don't know the value error
I compared the speed of Hash with Topaz, Ruby and Python
I tried scraping the ranking of Qiita Advent Calendar with Python
Python basics ⑤
I checked the distribution of the number of video views of "Flag-chan!" [Python] [Graph]
I want to know the weather with LINE bot feat.Heroku + Python
I compared the calculation time of the moving average written in Python