1
嗨〜我正在處理我的數據。熊貓條件語句問題
我想用條件語句提取數據
這是我的代碼。
# -*- coding: utf-8 -*-
import pandas as pd
import numpy as np
import os
join_file = r'D:\handling data\complete data\조인\after_join.csv'
pwd = os.getcwd()
os.chdir(os.path.dirname(join_file))
join_data = pd.read_csv(os.path.basename(join_file), sep=',', encoding='utf-8')
print(join_data.head())
join_data['cluster_z'] = 4 # 둘다 하락세
join_data['cluster_z'][((join_data['cluster_x'] == 3 | join_data['cluster_x'] == 2 | join_data['cluster_x'] == 4)
& (join_data['cluster_y'] == 3 | join_data['cluster_y'] == 1))] = 1 # 다 상승세
join_data['cluster_z'][((join_data['cluster_x'] == 1 | join_data['cluster_x'] == 5)
& (join_data['cluster_y'] == 3 | join_data['cluster_y'] == 1))] = 2 # 전체 하락세, 점포당 상승세
join_data['cluster_z'][((join_data['cluster_x'] == 3 | join_data['cluster_x'] == 2 | join_data['cluster_x'] == 4)
& (join_data['cluster_y'] == 2 | join_data['cluster_y'] == 4))] = 3 # 전체 상승세, 점파당 하락세
print(join_data.head())
和執行第二打印後(join_data.head())。 我喜歡的圖片
我怎樣才能解決這個問題的錯誤? 提前致謝。
謝謝~~你這麼大的傢伙! 有很多方法來處理它。哈哈。 你怎麼知道很多方法。謝謝~~ 有一個美好的一天~~ –