将多列数据合并成一列的方法有多种,以下是其中的几种常见方法:
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]
这些方法可以根据具体需求灵活选择使用。