for i in range(len(handled_ls.index)): Domestic_list.loc[handled_ls.index[i], 'name'] = handled_ls.values[i]
时间: 2024-04-12 21:33:07 浏览: 14
这是一个Python代码片段,它的作用是将一个名为 `handled_ls` 的数据集中的值逐行赋值给名为 `Domestic_list` 的数据集的 `name` 列。`handled_ls.index` 是 `handled_ls` 数据集的索引,`handled_ls.values[i]` 是 `handled_ls` 数据集第 `i` 行的值。整个循环遍历了 `handled_ls.index`,将对应行的值赋给了 `Domestic_list` 的相应行的 `name` 列。
相关问题
WARNING:tensorflow:From /root/miniconda3/envs/myconda/lib/python3.5/site-packages/tensorflow/python/ops/resource_variable_ops.py:435: colocate_with (from tensorflow.python.framework.ops) is deprecated and will be removed in a future version. Instructions for updating: Colocations handled automatically by placer. WARNING:tensorflow:From /root/miniconda3/envs/myconda/lib/python3.5/site-packages/tensorflow/python/keras/layers/core.py:143: calling dropout (from tensorflow.python.ops.nn_ops) with keep_prob is deprecated and will be removed in a future version. Instructions for updating: Please use `rate` instead of `keep_prob`. Rate should be set to `rate = 1 - keep_prob`.
这些warning信息是TensorFlow的版本更新导致的,不会影响代码的运行。第一个warning是因为在TensorFlow 2.0中,使用tf.compat.v1.placeholder()函数代替原来的tf.placeholder()函数,而colocate_with参数已经不再使用,因此会有这个warning。第二个warning是因为在TensorFlow 2.0中,使用tf.nn.dropout()函数代替原来的keras.layers.Dropout()函数,而keep_prob参数已经被rate参数代替,因此会有这个warning。如果想要避免这些warning信息,可以考虑更新代码中的相关函数。
在不改变代码本意的前提下,用另一种方式重写代码:import pandas as pd import numpy as np from sklearn.preprocessing import Imputer from sklearn.model_selection import train_test_split df_table_all = pd.read_csv("D:\python_pytharm\datasets\chapter3_data_handled\train_all.csv", index_col=0) df_table_all = df_table_all.drop(['LOAN_DATE_x'], axis=1) df_table_all = df_table_all.drop(['LOAN_DATE_y'], axis=1) df_table_all = df_table_all.dropna(axis=1,how='all') columns = df_table_all.columns imr = Imputer(missing_values='NaN', strategy='mean', axis=0) df_table_all = pd.DataFrame(imr.fit_transform(df_table_all.values)) df_table_all.columns = columns df_table_all.to_csv("D:\python_pytharm\datasets\chapter3_data_handled\trainafter.csv")
import pandas as pd
import numpy as np
from sklearn.impute import SimpleImputer
from sklearn.model_selection import train_test_split
# 读取数据
df_table_all = pd.read_csv("D:\python_pytharm\datasets\chapter3_data_handled\train_all.csv", index_col=0)
# 删除指定列
df_table_all = df_table_all.drop(['LOAN_DATE_x', 'LOAN_DATE_y'], axis=1)
# 删除所有值均为空的列
df_table_all = df_table_all.dropna(axis=1, how='all')
# 使用均值填充缺失值
imr = SimpleImputer(missing_values=np.nan, strategy='mean')
df_table_all = pd.DataFrame(imr.fit_transform(df_table_all))
# 重置列名并保存
df_table_all.columns = [str(i) for i in range(df_table_all.shape[1])]
df_table_all.to_csv("D:\python_pytharm\datasets\chapter3_data_handled\trainafter.csv", index=False)