Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/299.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/excel/29.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 将文本从一个单元格复制到另一个单元格而不删除原始内容_Python_Excel_Pandas - Fatal编程技术网

Python 将文本从一个单元格复制到另一个单元格而不删除原始内容

Python 将文本从一个单元格复制到另一个单元格而不删除原始内容,python,excel,pandas,Python,Excel,Pandas,我有7列,每列有一百万行数据 我需要复制第2、3、4、5、6、7列中的数据,并将其放在第1列内容的末尾。这将导致列1的原始内容(100万行)加上其余列的额外内容(600万行) 我想改变这一点: A B C 1 4 7 2 5 8 3 6 9 为此: A 1 2 3 4 5 6 7 8 9 我尝试使用熊猫,但它没有给我想要的输出。我没有按时间顺序从1到9排序,而是使用下面的代码按行排序(1,4,7,2,5,8,3,6,9)。你有没有办法把它做好 import pandas as

我有7列,每列有一百万行数据

我需要复制第2、3、4、5、6、7列中的数据,并将其放在第1列内容的末尾。这将导致列1的原始内容(100万行)加上其余列的额外内容(600万行)

我想改变这一点:

A  B  C
1  4  7
2  5  8
3  6  9
为此:

A
1
2
3
4
5
6
7
8
9
我尝试使用熊猫,但它没有给我想要的输出。我没有按时间顺序从1到9排序,而是使用下面的代码按行排序(1,4,7,2,5,8,3,6,9)。你有没有办法把它做好

import pandas as pd

df = pd.read_excel('filename.xlsx', sheet_name='Sheet1')
df = df.stack().reset_index(drop=True)


df.to_excel("output.xlsx")

请尝试使用pd.melt

df_new = pd.melt(df).drop("variable", axis=1)

print(df_new)

   value
0      1
1      2
2      3
3      4
4      5
5      6
6      7
7      8
8      9

excel文件中的数据是什么样的?