Get the App
SLTechnology News&Howtos  ›  Development  › 

How to operate on every data in Series by python

Shulou Source: shulou.com Published: 2022-06-01 13:04:42 09月27日 Update

Most people don't understand the knowledge points of this article "how python does operations on every data in Series", so Xiaobian summarizes the following contents for everyone. The contents are detailed, the steps are clear, and they have certain reference value. I hope everyone can gain something after reading this article. Let's take a look at this article "how python does operations on every data in Series".

problem description

Recently ~ found that the operation of elements in series is quite complex, for loop + Series.iloc[i] will occur stuck situation, then lambda is the solution:

error 1

ratings['timestamp'] = ratings['timestamp'].apply(ratings['timestamp'].iloc[i].strftime("%Y-%m-%d %H:%M:%S", ts) for i in range(len(ratings)))TypeError: 'generator' object is not callable

Applying lambda directly is equivalent to applying each element of each line one by one:

ratings_sub['timestamp'] = ratings_sub['timestamp'].apply(lambda x:time.strftime('%Y/%m/%d',time.localtime(x)))

Supplement: DataFrame and Series numerical operations

Principle 1:

The result of the operation returns the index of all occurrences

Principle 2:

Identical index addition

Principle 3:

Any value doing arithmetic with nan results in nan

The above is about the content of this article on "how python does operations on every data in Series". I believe everyone has a certain understanding. I hope the content shared by Xiaobian will be helpful to everyone. If you want to know more relevant knowledge, please pay attention to the industry information channel.

Tags: Operations content data principles elements articles knowledge articles indexes results complexity same one line value method most that is numerical values more steps Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno NVidia Shulou Information macOS Shulou Technology MySQL