我想将年龄范围转换为年龄数值。我使用def Age(x)和If语句进行转换,但是它不起作用并给出错误的结果。 我附加了我执行的步骤和结果的图像。 我使用的数据集是BlackFriday。 请帮助我澄清错误。 谢谢! enter image description here
答案 0 :(得分:1)
鉴于SshClient client = SshClient.setupDefaultClient();
// override any default configuration...
client.setSomeConfiguration(...);
client.setOtherConfiguration(...);
client.start();
结果中显示的内容,年龄为try (ClientSession session = client.connect(user, host, port).verify(timeout).getSession()) {
session.addPasswordIdentity(password);
session.auth.verify(timeout);
// User-specific factory
try (SftpClient sftp = DefaultSftpClientFactory.INSTANCE.createSftpClient(session)) {
// use sftp here
}
}
的简单str.extract
和fillna
似乎可以做到:
// calculate the start timestamp
$startdatetime = strtotime($startTimeInput);
// calculate the end timestamp
$enddatetime = strtotime($endTimeInput);
// calulate the difference in seconds
$difference = $enddatetime - $startdatetime;
// hours is the whole number of the division between seconds and SECONDS_PER_HOUR
$hoursDiff = $difference / 3600;
// and the minutes is the remainder
$minutesDiffRemainder = $difference % 3600;
// output the result
echo $hoursDiff . "hours " . $minutesDiffRemainder . "mins";
让我们考虑以下示例:
$datetime1 = new DateTime($startTimeInput);
$datetime2 = new DateTime($endTimeInput);
$interval = $datetime1->diff($datetime2);
echo $interval->format('%Y years, %M months, %D days, %I minutes, %S seconds');
答案 1 :(得分:0)
一个简单的函数,将age_range修改为:
这是我们的年龄范围
temp_df['age_range'].unique()
array([70, '18-25', '26-35', '36-45', '46-55', '56-70'], dtype=object)
修改年龄的功能
def mod_age(df):
for i in range(df.shape[0]):
if(df.loc[i,'age_range']==70):
df.loc[i,'age_range']=70
elif(df.loc[i,'age_range']=='18-25'):
df.loc[i,'age_range']=(18+25)//2
elif(df.loc[i,'age_range']=='26-35'):
df.loc[i,'age_range']=(26+35)//2
elif(df.loc[i,'age_range']=='36-45'):
df.loc[i,'age_range']=(36+45)//2
elif(df.loc[i,'age_range']=='46-55'):
df.loc[i,'age_range']=(46+55)//2
elif(df.loc[i,'age_range']=='56-70'):
df.loc[i,'age_range']=(56+75)//2
age_range family_size marital_status sum
2 70 2 Single 4
25 40 4 Single 2
5 21 2 Married 4
32 50 3 Single 3
13 30 2 Single 5