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

Python系列元组数据帧

Python系列元组数据帧,python,pandas,dataframe,tuples,Python,Pandas,Dataframe,Tuples,我不知怎的得到了一个以索引为元组的序列,其中数据为数字。我想通过删除元组[0]值,将其转换为一个索引为单个字符串的序列 非常感谢 您需要通过str[1]选择元组的第二个值: s.index = s.index.str[1] 样本: s = pd.Series([80,79,70], index=[('total','Mumbai'),('total','Chennai'),('total','Royal')]) print (s) (total, Mumbai)

我不知怎的得到了一个以索引为元组的序列,其中数据为数字。我想通过删除元组[0]值,将其转换为一个索引为单个字符串的序列


非常感谢

您需要通过
str[1]
选择元组的第二个值:

s.index = s.index.str[1]
样本:

s = pd.Series([80,79,70], 
              index=[('total','Mumbai'),('total','Chennai'),('total','Royal')])
print (s)
(total, Mumbai)     80
(total, Chennai)    79
(total, Royal)      70
dtype: int64

s.index = s.index.str[1]
print (s)
Mumbai     80
Chennai    79
Royal      70
dtype: int64
另一个解决方案包括:


谢谢。这很有效。我没有使用.str函数。您可能应该在问题中包含链接中显示的数据,以避免问题中出现死链接future@Raz0rwire我不熟悉stackoverflow,不知道你在建议什么。链接不起作用吗?或者你想让我把数据粘贴到问题本身。如果您也回复这个问题,将会很有帮助。提前谢谢。
s.index = s.index.map(lambda x: x[1])
print (s)
Mumbai     80
Chennai    79
Royal      70
dtype: int64