同じ列名を持つパンダデータフレームを作成することができました。 パンダのデータフレームにはこれが正常ですか? 2つのカラムのどちらか一方のみを選択できますか? 同じ名前を使用すると、結果としてデータフレームの両方の列が出力として生成されますか?同一の列名を持つpandaデータフレーム - 有効なプロセスですか?
下記の例:
# 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
をしかし、私は推測します名前だけで個別にアクセスすることはできませんか? –
いいえ、その名前はラベルであり、両方の列には同じラベルが付けられています。あなたはそこのインデックス値を経由してアクセスすることができます。 –