简体   繁体   English

熊猫列和行存在

[英]Pandas Column and Row exists

This is going to be hard for me to explain....but here I go... 这对我来说很难解释....但是我在这里...

I have two CSV files that I load in via PANDAS, but they are not the same "shape" We shall call then CSV1 and CSV2 我有两个通过PANDAS加载的CSV文件,但它们不是相同的“形状”,我​​们将分别调用CSV1和CSV2

I take two values from CSV1 and check to see if they exist in CSV2 We shall call the values VAL1 and VAL2; 我从CSV1中获取两个值,并检查它们是否存在于CSV2中。我们将分别称为VAL1和VAL2; they are all floating point numbers to three decimal points. 它们都是浮点数到小数点后三位。

assuming it exists in CSV2, VAL1 should be located somewhere in the first "column". 假设它存在于CSV2中,则VAL1应该位于第一个“列”中的某个位置。

assuming it exists in CSV2, VAL2 should be an actual column header 假设它存在于CSV2中,则VAL2应该是实际的列标题

For testing purposes i have ensured that the data in the two files are like-for-like, however when i run the scrip it is not finding a match on most of the values 为了进行测试,我确保两个文件中的数据是相同的,但是当我运行脚本时,它找不到大多数值的匹配项

import pandas as pd

_new = pd.read_csv('02 dump/reputation.csv', sep=';', float_precision='round_trip')
_data = pd.read_csv('00 data/confdata.csv', sep=';', float_precision='round_trip')

def confupdate():
    print(a)
    print("update")

def confnew():
    print(a)
    print("added")



for a,b in zip(_new['LAT'].values, _new['LON'].values): 
    print(a, b)

    if str(a) in str(_data['LAT'].values) and str(b) in str(_data.columns):

        confupdate()

    if str(a) not in str(_data['LAT'].values) and str(b) not in str(_data.columns):

        confnew()

    if str(a) not in str(_data['LAT'].values) or str(b) not in str(_data.columns):

        confnew()

I think it has something to do with float_precision='round_trip' in that it only affects how my floating point number is displayed though in the background the numbers are still not matching 我认为这与float_precision ='round_trip'有关,因为它仅影响我的浮点数的显示方式,尽管在后台数字仍然不匹配

Any ideas? 有任何想法吗?

I am 10 minute into a train journey, I settle down to take another crack at my problem and I almost immediately see whats wrong... 我距火车旅行只有10分钟的路程,我安顿下来了,以解决我的问题,我几乎立刻就发现出了什么问题...

..I am missing ".values" in "_data.columns" The IF statements should infact read: ..我在“ _data.columns”中缺少“ .values”。IF语句实际上应为:

if str(a) in str(_data['LAT'].values) and str(b) in str(_data.columns.value):

amazing how fresh eyes make a difference; 令人惊讶的是新鲜的眼睛如何产生影响; annoying how much time i wasted yesterday 讨厌我昨天浪费了多少时间

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM