ico*_*aos 4 python dataframe pandas
我试图将zipcodes缩短为各种文件,但我一直在努力
ValueError:无法从重复轴重新索引
我已经阅读了Stackoverflow上的其他文档,但我还没有弄清楚为什么它的重复轴.
import csv
import pandas as pd
from pandas import DataFrame as df
fp = '/Users/User/Development/zipcodes/file.csv'
file1 = open(fp, 'rb').read()
df = pd.read_csv(fp, sep=',')
df = df[['VIN', 'Reg Name', 'Reg Address', 'Reg City', 'Reg ST', 'ZIP',
'ZIP', 'Catagory', 'Phone', 'First Name', 'Last Name', 'Reg NFS',
'MGVW', 'Make', 'Veh Model','E Mfr', 'Engine Model', 'CY2010',
'CY2011', 'CY2012', 'CY2013', 'CY2014', 'CY2015', 'Std Cnt',
]]
#reader.head(1)
df.head(1)
zipBlue = [65355, 65350, 65345, 65326, 65335, 64788, 64780, 64777, 64743,
64742, 64739, 64735, 64723, 64722, 64720]
Run Code Online (Sandbox Code Playgroud)
还包含zipGreen, zipRed, zipYellow, ipLightBlue
但未包括在示例中.
def IsInSort():
blue = df[df.ZIP.isin(zipBlue)]
green = df[df.ZIP.isin(zipGreen)]
red = df[df.ZIP.isin(zipRed)]
yellow = df[df.ZIP.isin(zipYellow)]
LightBlue = df[df.ZIP.isin(zipLightBlue)]
def SaveSortedZips():
blue.to_csv('sortedBlue.csv')
green.to_csv('sortedGreen.csv')
red.to_csv('sortedRed.csv')
yellow.to_csv('sortedYellow.csv')
LightBlue.to_csv('SortedLightBlue.csv')
IsInSort()
SaveSortedZips()
Run Code Online (Sandbox Code Playgroud)
1864#试图重新索引一个带有重复项的轴1865
如果不是self.is_unique和len(索引器): - > 1866引发ValueError("不能从重复的轴重新索引")1867 1868 def reindex(self,target,method = None, level = None,limit = None):ValueError:无法从重复轴重新索引
fir*_*ynx 11
我很确定你的问题与你的面具有关
df = df[['VIN', 'Reg Name', 'Reg Address', 'Reg City', 'Reg ST', 'ZIP',
'ZIP', 'Catagory', 'Phone', 'First Name', 'Last Name', 'Reg NFS',
'MGVW', 'Make', 'Veh Model','E Mfr', 'Engine Model', 'CY2010',
'CY2011', 'CY2012', 'CY2013', 'CY2014', 'CY2015', 'Std Cnt',
]]
Run Code Online (Sandbox Code Playgroud)
'ZIP'在那里两次.删除其中一个应解决问题.
错误ValueError: cannot reindex from a duplicate axis是这些非常非常神秘的pandas错误之一,它根本不会告诉你错误是什么.
该错误通常与在操作之前或之后(内部)命名相同的两列相关.
| 归档时间: |
|
| 查看次数: |
7894 次 |
| 最近记录: |