[英]How to code all labels in list of pandas dataframes?
Parse the list of pandas dataframes from API.解析来自 API 的 pandas 数据帧列表。 I need them to put int autoencoder which fits data with shape (100, 36, 18)我需要他们放置 int 自动编码器,它适合具有形状 (100, 36, 18) 的数据
#encoder
input_sig = Input(shape=(num_events, features))
conv1 = Conv1D(32, 3, activation='relu', padding='same')(input_sig)
pool1 = MaxPooling1D(pool_size=2)(conv1)
conv2 = Conv1D(64, 3, activation='relu', padding='same')(pool1)
pool2 = MaxPooling1D(pool_size=2)(conv2)
conv3 = Conv1D(128, 3, activation='relu', padding='same')(pool2)
#decoder
conv4 = Conv1D(128, 3, activation='relu', padding='same')(conv3)
up1 = UpSampling1D(2)(conv4)
conv5 = Conv1D(64, 3, activation='relu', padding='same')(up1)
up2 = UpSampling1D(2)(conv5)
decoded = Conv1D(features, 3, activation='relu', padding='same')(up2)
model= Model(input_sig, decoded)
model.compile(loss='mean_squared_error', optimizer = RMSprop())
model.summary()
X_train, X_test, y_train, y_test = train_test_split(df_2,
df_2,
test_size=0.2,
random_state=50)
So I need to code categorical parameters in all my dataframes.所以我需要在我的所有数据框中编码分类参数。 But it's encoded in different values.但它以不同的值编码。 It's strongly wrong..: For example :这是非常错误的..:例如:
lst1 = {'Name': ['Java', 'Python', 'C', 'C++',
'JavaScript']}
lst2 = {'Name': ['Scala', 'Python', 'C', 'C++',
'JavaScript', 'Node', 'Text']}
dframe1 = pd.DataFrame(lst1)
dframe2 = pd.DataFrame(lst2)
dframe1['Name'] = LabelEncoder().fit_transform(dframe1['Name'])
dframe2['Name'] = LabelEncoder().fit_transform(dframe2['Name'])
asd = [dframe1,dframe2]
I need some function, that encodes the value 'Python' in both dataframes into the same value.我需要一些 function,它将两个数据帧中的值“Python”编码为相同的值。 How can I do this?我怎样才能做到这一点?
Are the names in lst1
and lst2
fixed? lst1
和lst2
中的名称是否固定? Will there be more names in the future?以后还会有更多的名字吗?
If not, what you have to do is get all the unique names/categories, and fit the LabelEncoder
.如果没有,您要做的是获取所有唯一名称/类别,并适合LabelEncoder
。 For example,例如,
names = dframe1['Name'].values.tolist() + dframe2['Name'].values.tolist()
enc = LabelEncoder()
enc.fit(names)
dframe1['Name'] = enc.transform(dframe1['Name'])
dframe2['Name'] = enc.transform(dframe2['Name'])
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.