Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby-on-rails-4/2.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/powershell/12.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
Pandas 如何格式化/连接数据帧中的数据?_Pandas - Fatal编程技术网

Pandas 如何格式化/连接数据帧中的数据?

Pandas 如何格式化/连接数据帧中的数据?,pandas,Pandas,在R中,我要做的是这样的: df$C <- sprintf("%02d-%02d", df$A, df$B) 在pandas中 df.apply(lambda x : "%02d-%02d" % (x['A'],x['B']),axis=1) Out[218]: 0 01-04 1 02-05 2 03-06 dtype: object 妈的,我知道这必须很简单。 df.apply(lambda x : "%02d-%02d" % (x['A'],x['B'])

在R中,我要做的是这样的:

df$C <- sprintf("%02d-%02d", df$A, df$B)

pandas中

df.apply(lambda x :  "%02d-%02d" % (x['A'],x['B']),axis=1)
Out[218]: 
0    01-04
1    02-05
2    03-06
dtype: object

妈的,我知道这必须很简单。
df.apply(lambda x :  "%02d-%02d" % (x['A'],x['B']),axis=1)
Out[218]: 
0    01-04
1    02-05
2    03-06
dtype: object
In [1]: import pandas as pd                                                                                                                                                                                 

In [2]: df = pd.DataFrame({"A": [1,2,3], "B": [4,5,6]})

In [9]: df['C']= df.apply(lambda x:"{:02d}-{:02d}".format(x['A'],x['B']), axis=1)                                                                                                                           

In [10]: df                                                                                                                                                                                                 
Out[12]: 
A  B      C
0  1  4  01-04
1  2  5  02-05
2  3  6  03-06