[英]Drop column from tuple list in Pandas dataframe
This is my tuple I guess我猜这是我的元组
df = [(1.8799187420058687, 1), (1.5963945918878317, 2)]
The type of df shows up as this df 的类型显示如下
print(type(df))
<type 'list'>
My goal is to remove the second variable column displayed as 1 and 2
我的目标是删除显示为1 and 2
的第二个变量列
This is how I came up to the result (if that can help)这就是我得出结果的方式(如果有帮助的话)
df = df.groupby('CBF_01').mean()
df = list(zip(df,df.index))
Expected output预期产出
df = (1.8799187420058687,1.5963945918878317)
loop through each tuple, save the first value in a list and convert it to tuple.循环遍历每个元组,将第一个值保存在列表中并将其转换为元组。
new_df = tuple([x[0] for x in df])
output: (1.8799187420058687, 1.5963945918878317)
Depending on how big the dataset is, you can loop through the dataframe and drop those, for example:根据数据集的大小,您可以遍历数据框并删除它们,例如:
for i in range(len(df)-1):
df['CBF_01'][i] = df['CBF_01'][i][0]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.