將多列數(shù)據(jù)合并成一列的方法有多種,以下是其中的幾種常見(jiàn)方法:
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]
這些方法可以根據(jù)具體需求靈活選擇使用。