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

Big data's Analysis of practical Learning Notes based on python-DataFrame of pandas

2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

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

Then in the previous article, we went on to DataFrame in pandas. Without saying much, we went straight to the code with comments.

# the operation of dataframe is nothing more than adding, deleting, changing and checking

From pandas import Series

From pandas import DataFrame

Df=DataFrame ({'age':Series ([18d20 ~ 30]))

'name':Series ([' x1pm / x2pm / / x3'])

})

Print (df)

''

Access column: variable name [column name]

Access line: variable name [nRom] access line n to line mmur1

Access blocks (rows and columns): variable names .iloc [n1:n2, m1:m2] access data from N1 to N2-1 rows and M1 to m2-1 columns

Access the specified location: variable name .at [row index, column name]

''

# access column

A=df ['age']

Print (a)

# access lines

B=df [1:3]

Print (b)

# access block

C=df.iloc [0:4,0:2]

Print (c)

# access the specified location

D=df.at [0reachingname']

Print (d)

# add columns

Df ['address'] = [' Earth', 'moon', 'Mars']

Print (df)

# Delete columns

# del df ['address']

# add lines

Df.loclen (df)] = [40, 'x4mom,' Jupiter']

Print (df)

# Delete rows, according to row index

# df.drop (1)

Isn't it easy? As long as you have the foundation of python, you can do it in minutes.

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

Internet Technology

Wechat

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

12
Report