Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/308.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/4/powerbi/2.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将DataFrama中的行传输到列_Python_Pandas_Dataframe_Csv - Fatal编程技术网

如何使用Python将DataFrama中的行传输到列

如何使用Python将DataFrama中的行传输到列,python,pandas,dataframe,csv,Python,Pandas,Dataframe,Csv,我需要一些帮助 我有以下带有此数据框的CSV文件: 如何使用Python和Pandas传输第1周、第2周(…)列中案例的数据? 应该是这样的: x=( 透视表( 指数=[“城市”、“人口”], columns=“week”, values=“cases”, aggfunc=“max”, ) .添加前缀(“周”) .reset_index() .重命名_轴(“,轴=1) ) 打印(x) 印刷品: 城市人口第1周第2周 0 x 50000 5 10 1 y 88000 2 15

我需要一些帮助

我有以下带有此数据框的CSV文件:

如何使用Python和Pandas传输第1周、第2周(…)列中案例的数据? 应该是这样的:

x=(
透视表(
指数=[“城市”、“人口”],
columns=“week”,
values=“cases”,
aggfunc=“max”,
)
.添加前缀(“周”)
.reset_index()
.重命名_轴(“,轴=1)
)
打印(x)
印刷品:

城市人口第1周第2周
0 x 50000 5 10
1 y 88000 2 15