具有相同列名的熊猫数据框 - 这是有效的过程吗?

时间:2017-05-08 10:40:54

标签: python pandas multiple-columns

我能够生成一个具有相同列名的熊猫数据框。 大熊猫数据框是否正常? 我怎样才能选择两列中的一列? 使用相同的名称,结果是产生数据帧的两列?

以下示例:

# Producing a new empty pd dataset
dataset=pd.DataFrame()

# fill in a list with values to be added to the dataset later
cases=[1]*10

# Adding the list of values in the dataset, and naming the variable / column
dataset["id"]=cases

# making a list of columns as it is displayed below: 
data_columns = ["id", "id"]

# Then, we call the pd dataframe using the defined column names:
dataset_new=dataset[data_columns]

# dataset_new
# It has as a result two columns with identical names.
# How can I process only one of the two dataset columns?

   id  id
0   1   1
1   1   1
2   1   1
3   1   1
4   1   1
5   1   1
6   1   1
7   1   1

0 个答案:

没有答案