ThinkChat2.0新版上线,更智能更精彩,支持会话、画图、阅读、搜索等,送10W Token,即刻开启你的AI之旅 广告
``` #!/usr/bin/env python # -*- coding: utf-8 -*- # @Time : 2018/12/31 0031 下午 06:28 # @desc : pandas基础,Series,DataFrame # @File : pandasBase.py # @Software: PyCharm import pandas as pd import numpy as np s1=pd.Series([4,7,-5,3]) print(s1) s1.values print(s1.values) print(s1.index) s2=pd.Series([4.0,6.5,-0.54,4.3],index=['d','b','a','c']); print(s2) print(s2['b']) print(s2[['a','b','c']]) print('b' in s2) print('e' in s2) #Series可以看成是一个定长的有序字典 dict1={ 'apple':5, 'pen':3, 'applepen':10, } s3=pd.Series(dict1) print(s3) #DataFrame data={ 'year':[2014,2015,2016,2017], 'income':[10000,30000,50000,80000], 'pay':[5000,20000,30000,30000] } df1=pd.DataFrame(data) print(df1) df2=pd.DataFrame(np.arange(12).reshape(3,4)) print(df2) df3=pd.DataFrame(np.arange(12).reshape(3,4),index=['a','c','b'],columns=['2015','2016','2017','2018']) print(df3) # 列 print(df3.columns) # 行 print(df3.index) # 值 print(df3.values) print(df1.describe()) # 反转 print(df1.T) #对列进行排序 print(df3.sort_index(axis=1)) #行排序 print(df3.sort_index(axis=0)) # 按值排序 print(df3.sort_values(by='2017')) ~~~ ```