在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))只有返回系列的方法.
达到目标连接字符串的最佳方法是什么?
将元组中的值从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?
list ×1
pandas ×1
python ×1
python-2.7 ×1
python-3.x ×1
series ×1
string ×1
tuples ×1
unicode ×1