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

What is the use of DataFrame in Pandas

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

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

This article mainly introduces the use of DataFrame in Pandas, has a certain reference value, interested friends can refer to, I hope you can learn a lot after reading this article, the following let the editor take you to understand it.

Getting started exampl

Code block:

# basic operation of Pandas DataFrame import pandas as pdimport numpy as np# In [45]: data = {'Day': [1 Day': 2, 3, 4, 5, 5, 6, 7],' Visits': [23, 45, 12, 46, 88, 45, 98] 'Rates': [1.0In 2.1meme 2.5meme 2.2meme 4.3meme 4.5Magne5.0]} # use DataFrame to load data # In [46]: df = pd.DataFrame (data) # In [47]: df# View the first five pieces of data # In [48]: df.head () # View the last five pieces of data # In [49]: df.tail () # View the last two pieces of data # In [ 50]: df.tail (2) # use set_index () to set the index column of dataframe # In [51]: df.set_index ('Day') # # We continue to print the first five pieces of data # found that the index has not been changed to the Day# set above because using df.set_index (' Day') creates a new object # In [52]: df.head by default () # modify the code as above to make the index take effect # In [53]: df2 = df.set_index ('Day') df2.head () # We use the parameter inplace=True to do the same thing # means to modify the DataFrame without creating a new object # In [54]: df.set_index (' Day') Inplace=True) df.head () # print Visits column values # In [55]: df = pd.DataFrame (data) df ['Visits'] # In [56]: df.Visits# print both Visits and Rates values # In [57]: df [[' Visits'] 'Rates']] # convert the value of the Visits column to list# In [58]: df.Visits.tolist () # convert the Visits and Rates columns into the numpy array # In [59]: np.array (df [[' Visits','Rates']]) # load the numpy array into DataFrame# In [60]: df_new = pd.DataFrame (df [['Visits']) 'Rates']]) df_new thanks you for reading this article carefully I hope the article "what is the use of DataFrame in Pandas" shared by the editor will be helpful to you. At the same time, I also hope that you will support us and pay attention to the industry information channel. More related knowledge is waiting for you to learn!

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