程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式師世界 >> 編程語言 >  >> 更多編程語言 >> Python

Python Programming Language Learning: set a field as an index column in pandas, and specify the index column in dataframe

編輯:Python

Python Programming language learning : stay pandas Set a field as an index column in , And in dataframe Specify the index column in

Catalog

stay pandas Set a field as an index column in , And in dataframe Specify the index column in

#T1、 utilize pd.DataFrame The index column() function automatically specifies the index column

#T2、 utilize set_index Function to manually specify the index column


stay pandas Set a field as an index column in , And in dataframe Specify the index column in

#T1、 utilize pd.DataFrame The index column() function automatically specifies the index column

# encoding: utf-8
import pandas as pd
#T1、 utilize pd.DataFrame The index column() function automatically specifies the index column
df01=pd.read_csv('600519.csv')
df02 = pd.DataFrame(df01[' Opening price '].values,columns = [' Opening price '], index=df01[' date '])
print(df02.head())

 

#T2、 utilize set_index Function to manually specify the index column

#T2、 utilize set_index Function to manually specify the index column
df01=pd.read_csv('600519.csv')
df01 = df01.set_index(df01[' date '])
print(df01.head())


  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式師世界 All Rights Reserved