Python:使用整数作为列名是一种不好的做法吗?

2024-04-25 11:38:25 发布

您现在位置:Python中文网/ 问答频道 /正文

以下代码通过pandasmerge函数导致异常。你知道吗

first = pd.read_csv('https://raw.githubusercontent.com/AntoineGautier/Data/master/first.txt', header=None)
secnd = pd.read_csv('https://raw.githubusercontent.com/AntoineGautier/Data/master/secnd.txt', header=None)
common_cols = [c for c in first.columns if c in secnd.columns]
first.merge(secnd, on=common_cols, how='left', indicator=True)

以下不适用。你知道吗

first.columns = first.columns.astype('str')
secnd.columns = secnd.columns.astype('str')
common_cols = [c for c in first.columns if c in secnd.columns]
first.merge(secnd, on=common_cols, how='left', indicator=True)

因此,使用numpy.int64类型的列名被认为是一种不好的做法吗?你知道吗


Tags: columnscsvinhttpscomreaddataraw