我的数据类型为pandas.core.series.Series
。有两列。我想从
V1 V2
1000 1 2 3
1001 0 2
到
1000 \t 1 \t 2 \t 3
1001 \t 0 \t 2
我尝试了什么:
1.
list(result.columns.values)
result[list(result.columns.values)].str.split(' ').replace('/t')
2.
result['labels'].split(' ', expand=True)
3.
c = str(result['labels'])
c.split(' ')
我尝试过其他方法,例如使用awk
或正则表达式。不幸的是,我无法相信我没有在doc或stackoverflow上找到答案。
注意:变量数量会增加!
答案 0 :(得分:1)
如果列string
的类型为V1
,然后是astype
或{{3},则您可以通过replace
将这两个列与int
标记为print df
V1 V2
0 1000 1 2 3
1 1001 0 2
s = df['V1'].astype(str) + ' ' + df['V2']
print s.replace('\s+', r'\t')
0 1000 1 2 3
1 1001 0 2
dtype: object
print s.str.replace('\s+', r'\t')
0 1000\t1\t2\t3
1 1001\t0\t2
dtype: object
。 }:
'\t'
或许您需要str.replace
然后split
print df
V2
V1
1000 1 2 3
1001 0 2
df1 = df['V2'].str.split('\s+', expand=True)
print df1
0 1 2
V1
1000 1 2 3
1001 0 2 None
df1 = df1.fillna('').reset_index()
df1['V1'] = df1['V1'].astype(str)
df1 = df1.T.apply('\t'.join)
df1 = df1.str.strip('\t')
print df1
0 1000\t1\t2\t3
1 1001\t0\t2
dtype: object
:
@Override
public void onClick(View v) {
LayoutInflater layoutInflater = LayoutInflater.from(getApplicationContext());
View promptsView = layoutInflater.inflate(R.layout.fragment_additional_info, null);
LinearLayout containerLinear = (LinearLayout) promptsView.findViewById(R.id.linearLayoutLoadingProgressbarContainer);
Button buttonOk = (Button) promptsView.findViewById(R.id.buttonOk);
for (KeyValueString keyValueItem : info.getAdditionalInfo().getKeyValueString()) {
if (!keyValueItem.getKey().equals("fee")) {
View viewToAdd = layoutInflater.inflate(R.layout.template_key_value, null);
TextView tvKey = (TextView) viewToAdd.findViewWithTag("key");
tvKey.setText(keyValueItem.getKey());
TextView tvValue = (TextView) viewToAdd.findViewWithTag("value");
tvValue.setText(keyValueItem.getValue());
containerLinear.addView(viewToAdd);
}
}
final AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(GuestPayActivity.this);
alertDialogBuilder.setView(promptsView);
alertDialogBuilder.setNegativeButton(R.string.button_cancel,
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
dialog.cancel();
}
});
final AlertDialog alertDialog = alertDialogBuilder.create();
alertDialog.show();
}