小编cyc*_*out的帖子

Python Pandas将一系列字符串连接成一个字符串

在python pandas中,有一个str值的Series/dataframe列要组合成一个长字符串:

df = pd.DataFrame({'text' : pd.Series(['Hello', 'world', '!'], index=['a', 'b', 'c'])})
Run Code Online (Sandbox Code Playgroud)

目标:'Hello world!'

到目前为止,df['text'].apply(lambda x: ' '.join(x))只有返回系列的方法.

达到目标连接字符串的最佳方法是什么?

string string-concatenation series python-3.x pandas

8
推荐指数
2
解决办法
8205
查看次数

Python将元组值从unicode转换为str

将元组中的值从unicode转换为字符串的最佳方法是什么,当元组在列表中时,是否可以在不循环的情况下完成?

unicodedata.normalize('NKFD', x)只能采取unicode,而不是元组.数据集还包括浮点值.

unicode_tuple_list = [(u'text in unicode', u'more unicode'), (u'more text in unicode', u'even more unicode')]

print type(unicode_tuple_list)   # list - keep as list

print type(unicode_tuple_list[0])   # tuple - keep as tuple           

print type(unicode_tuple_list[0][0])   # unicode
Run Code Online (Sandbox Code Playgroud)

如何将所有这些价值观作为一个str

python unicode tuples list python-2.7

3
推荐指数
1
解决办法
3659
查看次数