我想从列表中的每个元素的列表和位置创建元组列表.这是我正在尝试的.
def func_ (lis):
ind=0
list=[]
for h in lis:
print h
return h
Run Code Online (Sandbox Code Playgroud)
让我们说功能论证:
lis=[1,2,3,4,5]
Run Code Online (Sandbox Code Playgroud)
我想知道如何使用ind.
期望的输出:
[(1,0),(2,1),(3,2),(4,3),(5,4)]
Run Code Online (Sandbox Code Playgroud) 我在这样的数据框中有一个字符串列(时间)。我想在数字之间加下划线并删除月份。
Time
2- 3 months
1- 2 months
10-11 months
4- 5 months
Desired output:
2_3
1_2
10_11
4_5
Run Code Online (Sandbox Code Playgroud)
这是我正在尝试的方法,但似乎没有用。
def func(string):
a_new_string =string.replace('- ','_')
a_new_string1 =a_new_string.replace('-','_')
a_new_string2= a_new_string1.rstrip(' months')
return a_new_string2
Run Code Online (Sandbox Code Playgroud)
并将功能应用于数据框。
df['Time'].apply(func)
Run Code Online (Sandbox Code Playgroud) 我运行以下代码以3乘3网格绘制直方图,用于9个变量.但是,它只绘制一个变量.
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
def draw_histograms(df, variables, n_rows, n_cols):
fig=plt.figure()
for i, var_name in enumerate(variables):
ax=fig.add_subplot(n_rows,n_cols,i+1)
df[var_name].hist(bins=10,ax=ax)
plt.title(var_name+"Distribution")
plt.show()
Run Code Online (Sandbox Code Playgroud) 我想知道下面的伪代码是如何工作的?如果有一个有效的例子,我很感激。
data want;
do until (last.var1);
do until (last.var2);
set have;
* other sas statements;
end;
end;
run;
Run Code Online (Sandbox Code Playgroud) 我有两个领域(体检日期和出生日期).我计算了年龄((体检日期 - 出生日期)/365.25).我想要做的是在单独的领域中计算年龄和月份的年龄.我不确定是否可以使用代码生成器或某种方式完成.