我有一个包含整数值的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) 我有一个想要清理的数据集。该数据集由 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)
这两种方法都有问题
不知何故,它将每个值检测为非数字,我的最终输出如下所示:

知道我哪里出错了吗?