我有 @foreach ($user['friends'] as $friend)
@if($friend['user_id'] == $myid)
@switch ($friend['reqs_status'])
case 0:
//show button already request sent
break;
case 1:
//show accept and reject request button
break;
case 2:
//meaning they are friends already
default:
# code...
break;
@endswitch
@elseif(empty($friends['user_id']))
//show send request button
@endif
@endforeach
值:
Series
我希望将此系列转换为dataframe列的名称。它应该是这样的:
0 1_AA
1 2_BB
2 3_CC
3 4_DD
有可能吗?
答案 0 :(得分:1)
可以使用columns
的{{1}} - 参数:
DataFrame
或直接传递给列表:
>>> import pandas as pd
>>> s = pd.Series(['a', 'b', 'c'])
>>> pd.DataFrame(columns=s)
Empty DataFrame
Columns: [a, b, c]
Index: []
答案 1 :(得分:0)
您可以使用dict.fromkeys
:
where('created_at < ?', self.created_at)
或collections.OrderedDict
,它可以保证您的值的顺序始终保持:
>>> import pandas as pd
>>> s = pd.Series(['1_AA', '2_BB', '3_CC', '4_DD'])
>>> pd.DataFrame(dict.fromkeys(s, [0])) # each column containing one zero - [0]
1_AA 2_BB 3_CC 4_DD
0 0 0 0 0
您还可以使用空列表作为>>> from collections import OrderedDict
>>> pd.DataFrame(OrderedDict.fromkeys(s, [0]))
1_AA 2_BB 3_CC 4_DD
0 0 0 0 0
的第二个参数:
fromkeys
但是这会创建一个空数据框 - 使用正确的列。