改写编码words=[] df = pd.read_excel("EcustNew.xls").astype(str) df.head() df.dropna() # 通过for循环遍历来进行所有标题的分词 for i, row in df.iterrows(): words.append(' '.join(jieba.cut(row['标题']))) # 将标题转换为数值型向量,建立词频矩阵 vect = CountVectorizer() X = vect.fit_transform(wor
时间: 2023-07-15 07:12:11 浏览: 47
ds)
words=[]
df = pd.read_excel("EcustNew.xls").astype(str)
df = df.dropna() # 去除缺失值
# 通过for循环遍历来进行所有标题的分词
for i, row in df.iterrows():
words.append(' '.join(jieba.cut(row['标题'])))
# 将标题转换为数值型向量,建立词频矩阵
vect = CountVectorizer()
X = vect.fit_transform(words)
相关问题
根据上述代码,改写下列程序try: df1 = pd.read_csv('image_3_2.txt', sep='\t', header=None, error_bad_lines=False, na_values='?') df2 = pd.read_csv('image_6.txt', sep='\t', header=None, error_bad_lines=False, na_values='?') tree = KDTree(df2.iloc[:, :2].values) k = 4 distances, indices = tree.query(df1.iloc[:, :2].values, k=k) values = df2.iloc[indices[:, 1:], 2].values mean_values = values.mean(axis=1) df1.iloc[:, 2] = mean_values df1.to_csv('4.txt', sep='\t', header=None, index=None) except Exception as e: print("Error: ", e)
根据上述代码,改写后的程序如下:
```
try:
points3D = pd.read_csv('points3D.txt', sep='\t', header=None, error_bad_lines=False, na_values='?')
skeleton = cv2.imread('skeleton.jpg', cv2.IMREAD_GRAYSCALE)
tree = KDTree(points3D.iloc[:, :2].values)
with open("./voc/skelon/3d/result.txt", 'w', encoding='utf-8') as f1:
for y in range(skeleton.shape[0]):
for x in range(skeleton.shape[1]):
if skeleton[y][x] == 255:
x_axis_coord, y_axis_coord = transform_xy(x, y)
query_point = [x_axis_coord, y_axis_coord]
dist, index = tree.query(query_point)
f1.write(str(points3D.iloc[index, 0]) + " " +
str(points3D.iloc[index, 1]) + " " +
str(points3D.iloc[index, 2]) + " " + '\n')
except Exception as e:
print("Error: ", e)
```
这段代码与原始代码类似,不过是将输入的数据文件和输出的文件名、格式都进行了修改以适应新的应用场景。同时,由于我们无法直接读取图像文件,需要使用cv2库里的imread函数获取二维骨架图像。最后,将得到的三维坐标写入到txt文件中。
改写成python伪代码:result = df[df['label'] == -1] result.to_excel('E:/project\\bird_data_process\\flight direction\\-1.xlsx', index=False)
```
result = df[df['label'] == -1]
result.to_excel('E:/project\\bird_data_process\\flight direction\\-1.xlsx', index=False)
```
可以改写为python伪代码:
```
# 根据label列筛选出标签为-1的行
result = df[df['label'] == -1]
# 将结果保存到Excel文件中,不包含索引列
result.to_excel('E:/project\\bird_data_process\\flight direction\\-1.xlsx', index=False)
```
相关推荐
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)