小编sat*_*ats的帖子

根据C中的字节数从char数组中复制整数

我有一个包含整数值的8个字节的字符数组.我需要将1个字节复制到一个整数变量,接下来的4个字节复制到不同的整数变量,接下来的3个字节复制到另一个整数变量.我使用过"memcpy",但结果不合适.

我的尝试:

    unsigned char bytes[8];
    int Data1 = 32769;
    int Data2 = 65535;

    int logic1 = 0;
    int logic2 = 0;
    int logic3 = 0;

    memcpy(&bytes[0], &Data1, sizeof(Data1));
    memcpy(&bytes[4], &Data2, sizeof(Data2));

//Value of bytes[] array after this operation is
//bytes[0] = 1
//bytes[1] = 128
//bytes[2] = 0
//bytes[3] = 0
//bytes[4] = 255
//bytes[5] = 255
//bytes[6] = 0
//bytes[7] = 0



    memcpy(&logic1,&bytes,1);
    memcpy(&logic2,&bytes + 1,4);
    memcpy(&logic3,&bytes + 5,1);

My output should be :
logic1 = bytes[0]
logic2 = …
Run Code Online (Sandbox Code Playgroud)

c memcpy

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

检查 pandas 数据框中的列值是否为数字

我有一个想要清理的数据集。该数据集由 54 列和 315 行组成。对于其中一列,我想知道该列中的所有值是否都是数字。我做了以下事情:

work_sheet = pd.read_excel('2006_sale.xlsx', sheet_name='Sheet1')
df = work_sheet.copy()
Run Code Online (Sandbox Code Playgroud)

尝试1

for idx,val in enumerate(df['LotArea']):
    if(not(str(val).isnumeric())):        # Check if a value is numeric or not
        df.at[idx,'LotArea'] = np.nan     # If the value is not numeric then replace it with null

Run Code Online (Sandbox Code Playgroud)

尝试2

for idx,val in enumerate(df['LotArea']):
    if(not(isinstance(val,float))):        # Check if a value is numeric or not
        df.at[idx,'LotArea'] = np.nan     # If the value is not numeric then replace it with null

Run Code Online (Sandbox Code Playgroud)

LotArea 的示例值为: 在此输入图像描述

这两种方法都有问题 不知何故,它将每个值检测为非数字,我的最终输出如下所示: 在此输入图像描述

知道我哪里出错了吗?

python pandas data-cleaning

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

标签 统计

c ×1

data-cleaning ×1

memcpy ×1

pandas ×1

python ×1