0

我对 Python 和 Stackoverflow 都很陌生,所以如果我忽略了任何事情,请接受我的道歉。

我只是想合并两个表。

表 1:收入国家

<class 'pandas.core.frame.DataFrame'>
Int64Index: 48 entries, 0 to 47
Data columns (total 2 columns):
State    48 non-null object
Mean     48 non-null float64
dtypes: float64(1), object(1)
memory usage: 1.1+ KB

    State       Mean
0   Alabama     51912.500000
1   Arizona     56918.401961
2   Arkansas    56431.216216
3   California  73346.414226
4   Colorado    70932.230769

表 2:生活成本

<class 'pandas.core.frame.DataFrame'>
RangeIndex: 50 entries, 0 to 49
Data columns (total 2 columns):
State             50 non-null object
Cost of living    50 non-null object
dtypes: object(2)
memory usage: 880.0+ bytes

    State       Cost of living
0   Alabama     46,055
1   Alaska      53,070
2   Arizona     43,278
3   Arkansas    46,672
4   California  51,386

使用以下代码:

netIncome = costOfLiving.merge(right=incomeStates, on="State", validate="1:m")

但是,我得到了一个非常令人失望的结果,合并表返回空值,只有标题。

<class 'pandas.core.frame.DataFrame'>
Index: 0 entries
Data columns (total 3 columns):
State             0 non-null object
Cost of living    0 non-null object
Mean              0 non-null float64
dtypes: float64(1), object(2)
memory usage: 0.0+ bytes

State   Cost of living  Mean

期望的结果是所有州的手段和生活成本各自值的数据框。与此类似的东西:

    State       Mean       Cost of living
0   Alabama     51912.500000   46,055
1   Alaska      NaN            53,070
2   Arizona     56918.401961   43,278
3   Arkansas    56431.216216   46,672
4   California  73346.414226   51,386
5   Colorado    70932.230769  

你有什么建议我做错了吗?

谢谢吨。

4

0 回答 0