小编lxd*_*ler的帖子

Pandas DataFrame中"axis"属性的含义是什么?

以下面的例子为例:

>>> df1 = pd.DataFrame({"x":[1, 2, 3, 4, 5], 
                        "y":[3, 4, 5, 6, 7]}, 
                      index=['a', 'b', 'c', 'd', 'e'])

>>> df2 = pd.DataFrame({"y":[1, 3, 5, 7, 9], 
                        "z":[9, 8, 7, 6, 5]}, 
                      index=['b', 'c', 'd', 'e', 'f'])

>>> pd.concat([df1, df2], join='inner')
Run Code Online (Sandbox Code Playgroud)

输出是:

   y
a  3
b  4
c  5
d  6
e  7
b  1
c  3
d  5
e  7
f  9
Run Code Online (Sandbox Code Playgroud)

由于axis=0是列,我认为concat()只考虑在两个数据帧中找到的.但是,实际输出会考虑在两个数据帧中找到的.

axis参数的确切含义是什么?

python axis dataframe pandas

20
推荐指数
4
解决办法
4万
查看次数

{:02d}在Python中意味着什么

很难找到有关{:}在线的信息我在下面看到了一些代码:

def dateformat(date):
    day, month, year=date.split('/')
    return "{:4d}{:02d}{:02d}".format(int(year),int(month),int(day))
Run Code Online (Sandbox Code Playgroud)

我有点知道它正在0以格式填充领先,但我不知道做什么'02''d'{:02d}做什么?

python string format

2
推荐指数
1
解决办法
2万
查看次数

如何在Python中解释解释timeit命令

例如,我有一个列表:

L=[-13, -24, -21, -3, -23, -15, -14, -27, -13, -12]
Run Code Online (Sandbox Code Playgroud)
  1. 如果在%timeit -n 10 myList = [item for item in L if item < 15] 输出中键入10 loops, best of 3: 1.25 µs per loop

  2. 如果我输入myGen = (item for item in L if item < 15) 输出是1000000 loops, best of 3: 561 ns per loop

在情况2中,我不明白为什么生成器需要1000000个循环而不是10个循环?“ 3中最佳”是什么意思?我如何算出每个公共区域所需的总秒数,例如案例1的10 * 1.25 = 12.5 us?

python time generator python-2.x ipython

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

标签 统计

python ×3

axis ×1

dataframe ×1

format ×1

generator ×1

ipython ×1

pandas ×1

python-2.x ×1

string ×1

time ×1