import pandas as pd
# example with only two locations in column 0 of a DataFrame
df = pd.DataFrame([75600, 1200])
# convert all entries in column 0 to string, adding '0' to the beginning when postal code < 10000
df = df[0].apply(lambda x: '0' + str(x) if x < 10000 else str(x))
因此,据我所知,一个可能的解决方案是在邮政编码为<;10000是这样吗?一种方法是将所有条目转换为字符串
如果这不是你想要的解决方案,请让我知道
我建议创建一个新的专栏,而不是尝试动态替换
像这样的
例如:
df的解=df[0]。应用(lambda x:'0'+str(x),如果x<;10000 else str(x))是完美的。它将代码转换成完整的字符串,然后我可以找到与国家邮政信息相对应的GPS坐标。 非常感谢
相关问题 更多 >
编程相关推荐