In [1]: import pandas as pd
In [3]: aa={'one':[1,2,3],'two':[2,3,4],'three':[3,4,5]}
In [4]: bb=pd.DataFrame(aa)
In [5]: bb
Out[5]:
one three two
0 1 3 2
1 2 4 3
2 3 5 4`
bb=pd.DataFrame(aa,index=['first','second','third']) bb Out[7]: one three two first 1 3 2 second 2 4 3 third 3 5 4
import numpy as np In [9]: del aa In [10]: aa=np.array([[1,2,3],[4,5,6],[7,8,9]]) In [11]: aa Out[11]: array([[1, 2, 3], [4, 5, 6], [7, 8, 9]]) In [12]: bb=pd.DataFrame(aa) In [13]: bb Out[13]: 0 1 2 0 1 2 3 1 4 5 6 2 7 8 9
bb=pd.DataFrame(aa,index=[22,33,44],columns=['one','two','three']) In [15]: bb Out[15]: one two three 22 1 2 3 33 4 5 6 44 7 8 9
bb=pd.DataFrame(aa,index=[22,33,44],columns=['one','two','three']) bb Out[15]: one two three 22 1 2 3 33 4 5 6 44 7 8 9 cc=bb[['one','three']].copy() Cc Out[17]: one three 22 1 3 33 4 6 44 7 9
cc['three'][22]=5 bb Out[19]: one two three 22 1 2 3 33 4 5 6 44 7 8 9 cc Out[20]: one three 22 1 5 33 4 6 44 7 9
bb['one'] Out[21]: 22 1 33 4 44 7 Name: one, dtype: int32
bb[['one','three']] Out[29]: one three 22 1 3 33 4 6 44 7 9
bb[1:3] Out[27]: one two three 33 4 5 6 44 7 8 9 bb[:1] Out[28]: one two three 22 1 2 3
bb.loc[[22,33]][['one','three']] Out[30]: one three 22 1 3 33 4 6
bb.loc[[22,33]][['one','three']]=[[2,2],[3,6]] In [32]: bb Out[32]: one two three 22 1 2 3 33 4 5 6 44 7 8 9
bb[['one','three']][:2] Out[33]: one three 22 1 3 33 4 6
In [34]: bb[['one','three']][:2]=[[2,2],[2,2]] -c:1: SettingWithCopyWarning: A value is trying to be set on a copy of a slice from a DataFrame. Try using .loc[row_index,col_indexer] = value instead F:Anacondalibsite-packagespandascoreframe.py:1999: SettingWithCopyWarning: A value is trying to be set on a copy of a slice from a DataFrame return self._setitem_slice(indexer, value)
bb.iloc[2:3,2:3] Out[36]: three 44 9 bb.iloc[1:3,1:3] Out[37]: two three 33 5 6 44 8 9 bb.iloc[0,0] Out[38]: 1
bb.iloc[0:4,0:2]=[[9,9],[9,9],[9,9]] In [45]: bb Out[45]: one two three 22 9 9 3 33 9 9 6 44 9 9 9
bb['new']=[2,3,4] bb Out[51]: one two three new 22 9 9 3 2 33 9 9 6 3 44 9 9 9 4 bb[['new','new2']]=[[2,3,4],[5,3,7]] KeyError: "['new' 'new2'] not in index"
aa={33:[234,44,55],44:[657,77,77],22:[33,55,457]}
In [58]: bb=bb.join(pd.DataFrame(aa.values(),columns=['hi','hello','ok'],index=aa.keys()))
In [59]: bb
Out[59]:
one two three new hi hello ok
22 9 9 3 2 33 55 457
33 9 9 6 3 234 44 55
44 9 9 9 4 657 77 77
bb.drop(['new','hi'],axis=1) Out[60]: one two three hello ok 22 9 9 3 55 457 33 9 9 6 44 55 44 9 9 9 77 77
bb.drop([22,33],axis=0) Out[61]: one two three new hi hello ok 44 9 9 9 4 657 77 77
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有