Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to operate on every data in Series by python

2025-02-23 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

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.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report