將多列數據合并成一列的方法有多種,以下是其中的幾種常見方法:
import pandas as pd
df = pd.DataFrame({'A': [1, 2, 3], 'B': [4, 5, 6], 'C': [7, 8, 9]})
new_column = pd.concat([df['A'], df['B'], df['C']], ignore_index=True)
import pandas as pd
df = pd.DataFrame({'A': [1, 2, 3], 'B': [4, 5, 6], 'C': [7, 8, 9]})
new_column = pd.melt(df)['value']
import numpy as np
array = np.array([[1, 4, 7], [2, 5, 8], [3, 6, 9]])
new_column = array.reshape(-1)
df = [[1, 4, 7], [2, 5, 8], [3, 6, 9]]
new_column = [value for sublist in df for value in sublist]
這些方法可以根據具體需求靈活選擇使用。