Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/348.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_Python 3.x_Pandas_Series - Fatal编程技术网

我在一个数据框中有两列,一列有列名,另一列没有列名。如何在python上命名它们?

我在一个数据框中有两列,一列有列名,另一列没有列名。如何在python上命名它们?,python,python-3.x,pandas,series,Python,Python 3.x,Pandas,Series,输入 输出 Fruit Apple 55 Orange 43 我需要相应地重命名列,请帮助我认为需要通过以下方式将系列转换为数据帧: Fruit Count Apple 55 Orange 43 所以需要df.columns=['Fruit','Count']?或者先df=df.reset\u index)不,它没有给出正确的输出,什么是print(df.info())或print(df.head().to\u dict())?RangeIndex:108

输入

输出

 Fruit 
    Apple   55
    Orange  43

我需要相应地重命名列,请帮助

我认为需要通过以下方式将
系列
转换为
数据帧

Fruit   Count
Apple   55
Orange  43

所以需要
df.columns=['Fruit','Count']
?或者先
df=df.reset\u index)
不,它没有给出正确的输出,什么是
print(df.info())
print(df.head().to\u dict())
?RangeIndex:1084个条目,0到1083个数据列(共2列):Fruit 1084个非空int64(Emptycolumn)1084个非空int64数据类型:int64(2)内存使用:17.0 KB NoneSo
df.columns=['Fruit','Count']
不工作?
df = df.reset_index(name='Count')