Python 从特定列开始的数据帧拆分
我有以下数据帧:Python 从特定列开始的数据帧拆分,python,pandas,Python,Pandas,我有以下数据帧: a b c d Unnamed: 5 1 43.91 -0.041619 43.91 -0.041619 43.91 2 43.39 0.011913 43.91 -0.041619 43.91 3 45.56 -0.048801 43.91 -0.041619 43.91 4 45.43 0.002857 43.91 -0.041619 43.91
a b c d Unnamed: 5
1 43.91 -0.041619 43.91 -0.041619 43.91
2 43.39 0.011913 43.91 -0.041619 43.91
3 45.56 -0.048801 43.91 -0.041619 43.91
4 45.43 0.002857 43.91 -0.041619 43.91
5 45.33 0.002204 43.91 -0.041619 43.91
6 45.68 -0.007692 43.91 -0.041619 43.91
7 46.37 -0.014992 43.91 -0.041619 43.91
8 48.04 -0.035381 43.91 -0.041619 43.91
9 48.38 -0.007053 43.91 -0.04161 43.91
我想通过按名称调用name列d
,来划分这个数据帧,并得到以下输出:
df1=
a b c
1 43.91 -0.041619 43.91
2 43.39 0.011913 43.91
3 45.56 -0.048801 43.91
4 45.43 0.002857 43.91
5 45.33 0.002204 43.91
6 45.68 -0.007692 43.91
7 46.37 -0.014992 43.91
8 48.04 -0.035381 43.91
9 48.38 -0.007053 43.91
df2=
d Unnamed: 5
1 -0.041619 43.91
2 -0.041619 43.91
3 -0.041619 43.91
4 -0.041619 43.91
5 -0.041619 43.91
6 -0.041619 43.91
7 -0.041619 43.91
8 -0.041619 43.91
9 -0.04161 43.91
是否可以使用pandas库实现此输出?如果需要,一个带有排除的
d
列的数据帧用于位置和选择方式,对于包含的,请参见选择方式:
df1=df.iloc[:,:4];df2=df.iloc[:,4::]
?
col = 'd'
df1 = df.iloc[:, :df.columns.get_loc(col)]
df2 = df.loc[:, col:]
print (df1)
a b c
1 43.91 -0.041619 43.91
2 43.39 0.011913 43.91
3 45.56 -0.048801 43.91
4 45.43 0.002857 43.91
5 45.33 0.002204 43.91
6 45.68 -0.007692 43.91
7 46.37 -0.014992 43.91
8 48.04 -0.035381 43.91
9 48.38 -0.007053 43.91
print (df2)
d Unnamed: 5
1 -0.041619 43.91
2 -0.041619 43.91
3 -0.041619 43.91
4 -0.041619 43.91
5 -0.041619 43.91
6 -0.041619 43.91
7 -0.041619 43.91
8 -0.041619 43.91
9 -0.041610 43.91