jiangjinghua
江jh
采纳率85.7%
2021-01-11 11:24

python pandas报错TypeError

100

重装系统之前没有这个错误,重装之后报这个错,我重装python,重新下载库,但不解决问题,别的电脑就能运行,求高手解决!

TypeError: int() argument must be a string, a bytes-like object or a number, not '_NoValueType'

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答

20条回答

  • qqzhuimengren PythonJavaC++go 4月前

    你这代码我运行的没有问题。

    应该是环境问题。

    先重装pandas,

    python运行其它没问题的话,就是pandas安装不全等问题

    点赞 2 评论 复制链接分享
  • weixin_43162240 Bryce__LY 4月前

    你安装一个anaconda呢 用anaconda的python试试

    点赞 1 评论 复制链接分享
  • weixin_43162240 Bryce__LY 4月前

    重装一下anaconda或者python  然后安装pandas和numpy应该就可以

    点赞 1 评论 复制链接分享
  • qqzhuimengren PythonJavaC++go 4月前

    使用pandas的代码呢
    错误信息要具体

    点赞 1 评论 复制链接分享
  • soar3033 soar3033 4月前

    在组策略里 把 计算机配置--windows设置--安全设置--本地策略--安全策略--网络安全:限制NTLM:传入NTLM流量  改成“允许所有”

    点赞 1 评论 复制链接分享
  • soar3033 soar3033 4月前

    卸载python,安装行的那台电脑的版本。不同的python版本有的时候会犯这种毛病。

    点赞 1 评论 复制链接分享
  • SoftwareTeacher SoftwareTeacher 4月前

    请问是到了哪一步出现这个问题的?你装的是什么版本? 其他安装信息呢? 

    点赞 1 评论 复制链接分享
  • jiangjinghua 江jh 4月前

    anaconda的方法的确管用

     

    点赞 评论 复制链接分享
  • jiangjinghua 江jh 4月前

    你们的回答我都点赞了,不过积分不多

    点赞 评论 复制链接分享
  • jiangjinghua 江jh 4月前

    成功了,谢谢

     

    点赞 评论 复制链接分享
  • jiangjinghua 江jh 4月前

    运行的非常慢,但是只能出此下策了。

    点赞 评论 复制链接分享
  • jiangjinghua 江jh 4月前

    好的

     

    点赞 评论 复制链接分享
  • jiangjinghua 江jh 4月前

    还是不行,我重装了python,pycharm,numpy,pandas,还是不行

    点赞 评论 复制链接分享
  • jiangjinghua 江jh 4月前

    好的,我试试重装

     

    点赞 评论 复制链接分享
  • jiangjinghua 江jh 4月前

    不管用啊·

    点赞 评论 复制链接分享
  • jiangjinghua 江jh 4月前

    soar,我用了你的方法

     

    点赞 评论 复制链接分享
  • jiangjinghua 江jh 4月前
    arr = [[
        "坝横",
        "坝纵",
        "高程",
        "type",
        "编号"
    ], [
        -5,
        21,
        1151,
        0,
        "J11"
    ], [
        -2.5,
        21,
        1141.75,
        0,
        "J12"
    ], [
        -2.5,
        41,
        1151,
        0,
        "J13"
    ], [
        -2.5,
        41,
        1134,
        0,
        "J14"
    ], [
        -0.5,
        61,
        1151,
        0,
        "J15"
    ], [
        -2.5,
        61,
        1125.1,
        0,
        "J16"
    ], [
        -0.5,
        76,
        1151,
        0,
        "J17"
    ], [
        -2.5,
        76,
        1124,
        0,
        "J18"
    ], [
        -0.5,
        92,
        1151,
        0,
        "J19"
    ], [
        -2.5,
        92,
        1122.25,
        0,
        "J20"
    ], [
        -0.5,
        102,
        1151,
        0,
        "J21"
    ], [
        -2.5,
        102,
        1124,
        0,
        "J22"
    ], [
        -5.5,
        119,
        1151,
        0,
        "J23"
    ], [
        1.5,
        119,
        1130.5,
        0,
        "J24"
    ], [
        1.5,
        136,
        1151,
        0,
        "J25"
    ], [
        -2.5,
        136,
        1130.5,
        0,
        "J26"
    ], [
        1.5,
        153,
        1151,
        0,
        "J27"
    ], [
        2.5,
        153,
        1130.5,
        0,
        "J28"
    ], [
        -0.5,
        167,
        1151,
        0,
        "J29"
    ], [
        -2.5,
        167,
        1138.75,
        0,
        "J30"
    ], [
        -3,
        28,
        1128.13,
        0,
        "J31"
    ], [
        -3,
        35,
        1120.48,
        0,
        "J32"
    ], [
        -3,
        49,
        1111.2,
        0,
        "J33"
    ], [
        -3,
        56,
        1102.8,
        0,
        "J34"
    ], [
        -3,
        85,
        1093.5,
        0,
        "J35"
    ], [
        -3,
        113,
        1106.75,
        0,
        "J36"
    ], [
        -3,
        157,
        1112.5,
        0,
        "J37"
    ], [
        -3,
        162,
        1112.5,
        0,
        "J38"
    ], [
        -3,
        173,
        1132.5,
        0,
        "J39"
    ], [
        -3,
        179,
        1144.5,
        0,
        "J40"
    ], [
        2.1,
        31,
        1124.05,
        5,
        "测压管P1"
    ], [
        2.1,
        51,
        1108,
        5,
        "测压管P2"
    ], [
        2.1,
        66,
        1098.4,
        5,
        "测压管P3"
    ], [
        2.1,
        89.5,
        1092.7,
        5,
        "测压管P4"
    ], [
        2.1,
        101,
        1096.2,
        5,
        "测压管P5"
    ], [
        2.1,
        108,
        1100.53,
        5,
        "测压管P6"
    ], [
        2.1,
        127.5,
        1109.2,
        5,
        "测压管P7"
    ], [
        2.1,
        144.5,
        1109.2,
        5,
        "测压管P8"
    ], [
        -2,
        84.25,
        1088.5,
        1,
        "M1"
    ], [
        5.5,
        84.25,
        1092,
        1,
        "M2"
    ], [
        25,
        84.25,
        1092,
        1,
        "M3"
    ], [
        45,
        84.25,
        1088.5,
        1,
        "M4"
    ], [
        -2,
        60,
        1094.2,
        1,
        "M5"
    ], [
        7,
        60,
        1094.2,
        1,
        "M6"
    ], [
        31,
        60,
        1094.2,
        1,
        "M7"
    ], [
        -1.5,
        84.25,
        1131,
        2,
        "J1"
    ], [
        -1.5,
        84.25,
        1122,
        2,
        "J2"
    ], [
        -1.5,
        84.25,
        1113,
        2,
        "J3"
    ], [
        3.5,
        84.25,
        1103,
        2,
        "J4"
    ], [
        27.52,
        84.25,
        1106,
        2,
        "J5"
    ], [
        -1.5,
        60,
        1138,
        2,
        "J6"
    ], [
        -1.5,
        60,
        1127,
        2,
        "J7"
    ], [
        -1.5,
        60,
        1116,
        2,
        "J8"
    ], [
        3.5,
        60,
        1107,
        2,
        "J9"
    ], [
        24.25,
        60,
        1111,
        2,
        "J10"
    ], [
        -2.5,
        84.25,
        1120,
        3,
        "E1"
    ], [
        -2.5,
        84.25,
        1120,
        3,
        "E1"
    ], [
        -2.5,
        84.25,
        1120,
        3,
        "E2"
    ], [
        8,
        84.25,
        1096.3,
        3,
        "E3"
    ], [
        28,
        84.25,
        1096.3,
        3,
        "E4"
    ], [
        -2.5,
        60,
        1122,
        3,
        "E5"
    ], [
        -1.5,
        60,
        1122,
        3,
        "E6"
    ], [
        9,
        60,
        1098.5,
        3,
        "E7"
    ], [
        28,
        60,
        1098.5,
        3,
        "E8"
    ], [
        -3,
        84.25,
        1128,
        4,
        "T1"
    ], [
        -3,
        84.25,
        1128,
        4,
        "T2"
    ], [
        10,
        84.25,
        1128,
        4,
        "T3"
    ], [
        -3.89,
        84.25,
        1120,
        4,
        "T4"
    ], [
        7,
        84.25,
        1120,
        4,
        "T5"
    ], [
        18,
        84.25,
        1120,
        4,
        "T6"
    ], [
        -5.24,
        84.25,
        1111,
        4,
        "T7"
    ], [
        7,
        84.25,
        1111,
        4,
        "T8"
    ], [
        17,
        84.25,
        1111,
        4,
        "T9"
    ], [
        25,
        84.25,
        1111,
        4,
        "T10"
    ], [
        -6.59,
        84.25,
        1102,
        4,
        "T11"
    ], [
        7,
        84.25,
        1102,
        4,
        "T12"
    ], [
        17,
        84.25,
        1102,
        4,
        "T13"
    ], [
        27,
        84.25,
        1102,
        4,
        "T14"
    ], [
        37,
        84.25,
        1102,
        4,
        "T15"
    ], [
        -2.92,
        60,
        1140,
        4,
        "T16"
    ], [
        -2.92,
        60,
        1128,
        4,
        "T17"
    ], [
        11,
        60,
        1128,
        4,
        "T18"
    ], [
        -4.49,
        60,
        1116,
        4,
        "T19"
    ], [
        8,
        60,
        1116,
        4,
        "T20"
    ], [
        20,
        60,
        1116,
        4,
        "T21"
    ], [
        -6.29,
        60,
        1104,
        4,
        "T22"
    ], [
        7,
        60,
        1104,
        4,
        "T23"
    ], [
        7,
        60,
        1104,
        4,
        "T23"
    ], [
        18,
        60,
        1104,
        4,
        "T24"
    ], [
        29,
        60,
        1104,
        4,
        "T25"
    ], [
        -3,
        84.25,
        1102.2,
        6,
        "N1"
    ], [
        10,
        84.25,
        1102.2,
        6,
        "N2"
    ], [
        20,
        84.25,
        1102.2,
        6,
        "N3"
    ], [
        30,
        84.25,
        1102.2,
        6,
        "N4"
    ], [
        -3,
        60,
        1105.2,
        6,
        "N5"
    ], [
        8,
        60,
        1105.2,
        6,
        "N6"
    ], [
        17,
        60,
        1105.2,
        6,
        "N7"
    ], [
        27,
        60,
        1105.2,
        6,
        "N8"
    ], [
        -3,
        84.25,
        1102.2,
        7,
        "S1-1"
    ], [
        -3,
        84.25,
        1102.2,
        7,
        "S1-2"
    ], [
        -3,
        84.25,
        1102.2,
        7,
        "S1-3"
    ], [
        -3,
        84.25,
        1102.2,
        7,
        "S1-4"
    ], [
        10,
        84.25,
        1102.2,
        7,
        "S2-1"
    ], [
        10,
        84.25,
        1102.2,
        7,
        "S2-2"
    ], [
        10,
        84.25,
        1102.2,
        7,
        "S2-3"
    ], [
        10,
        84.25,
        1102.2,
        7,
        "S2-4"
    ], [
        20,
        84.25,
        1102.2,
        7,
        "S3-1"
    ], [
        20,
        84.25,
        1102.2,
        7,
        "S3-2"
    ], [
        20,
        84.25,
        1102.2,
        7,
        "S3-3"
    ], [
        20,
        84.25,
        1102.2,
        7,
        "S3-4"
    ], [
        30,
        84.25,
        1102.2,
        7,
        "S4-1"
    ], [
        30,
        84.25,
        1102.2,
        7,
        "S4-2"
    ], [
        30,
        84.25,
        1102.2,
        7,
        "S4-3"
    ], [
        30,
        84.25,
        1102.2,
        7,
        "S4-4"
    ], [
        -3,
        60,
        1105.2,
        7,
        "S5-1"
    ], [
        -3,
        60,
        1105.2,
        7,
        "S5-2"
    ], [
        -3,
        60,
        1105.2,
        7,
        "S5-3"
    ], [
        -3,
        60,
        1105.2,
        7,
        "S5-4"
    ], [
        8,
        60,
        1105.2,
        7,
        "S6-1"
    ], [
        8,
        60,
        1105.2,
        7,
        "S6-2"
    ], [
        8,
        60,
        1105.2,
        7,
        "S6-3"
    ], [
        8,
        60,
        1105.2,
        7,
        "S6-4"
    ], [
        17,
        60,
        1105.2,
        7,
        "S7-1"
    ], [
        17,
        60,
        1105.2,
        7,
        "S7-2"
    ], [
        17,
        60,
        1105.2,
        7,
        "S7-3"
    ], [
        17,
        60,
        1105.2,
        7,
        "S7-4"
    ], [
        27,
        60,
        1105.2,
        7,
        "S8-1"
    ], [
        27,
        60,
        1105.2,
        7,
        "S8-2"
    ], [
        27,
        60,
        1105.2,
        7,
        "S8-3"
    ], [
        27,
        60,
        1105.2,
        7,
        "S8-4"
    ]
    ]
    
    
    # with open("./test.json", 'r') as load_f:
    #     load_dict = eval(load_f.read())
    #     print(load_dict)
    # data = load_dict
    # print(795,data)
    
    arr1 = arr[1:]
    
    
    import pandas as pd
    import numpy as np
    
    x_mean = np.mean([item[0] for item in arr1])
    y_mean = np.mean([item[1] for item in arr1])
    z_mean = np.mean([item[2] for item in arr1])
    pd.set_option('display.max_rows', 60000)
    pd.set_option('display.max_columns', 1000)
    
    
    # pos_ls = [(pos[0], pos[1], pos[2]) for index, pos in arr[1:]]
    
    
    def touying(a, b, c, d, x0, y0, z0):
        pingfanghe = a ** 2 + b ** 2 + c ** 2
        xp = ((b ** 2 + c ** 2) * x0 - a * (b * y0 + c * z0 + d)) / pingfanghe
        yp = ((a ** 2 + c ** 2) * y0 - b * (a * x0 + c * z0 + d)) / pingfanghe
        zp = ((a ** 2 + b ** 2) * z0 - c * (a * x0 + b * y0 + d)) / pingfanghe
        return xp, yp, zp
    
    
    # print('touying:', touying(0, 0, 1, -1, 1, 1, 3.8))
    # 投影到的平面
    a1 = 0.001
    b1 = 1
    c1 = 0.001
    d1 = 0
    # a1 = data[0] - x_mean
    # b1 = data[1] - y_mean
    # c1=data[2]-z_mean
    # a1x+b1y+c1z+d1=0
    # 原点
    x1 = 0.01
    y1 = 0.01
    if c1 == 0:
        c1 = 0.01
    z1 = -(a1 * x1 + b1 * y1 + d1) / c1
    print(837,z1)
    # -1
    # x轴上一点
    x2 = 1
    y2 = 0.01
    z2 = -(a1 * x2 + b1 * y2 + d1) / c1
    # -3
    # print(z2)
    # (x-x1)/(x2-x1)=(y-y1)/(y2-y1)=(z-z1)/(z2-z1)
    # (x-x1)(x2-x1)+(y-y1)(y2-y1)+(z-z1)(z2-z1)=0
    # x轴:(x-x1)/a2=(y-y1)/b2=(z-z1)/c2
    a2 = x2 - x1
    b2 = y2 - y1
    c2 = z2 - z1
    # print(a2,b2,c2)
    # 1,1,-2
    # y轴直线上一点
    x0 = 0.01
    # z0 = (x1 * x2 - x1 ** 2 - (y1 - y2) * d1 / b1 - y1 ** 2
    #       - y1 * y2 + z1 * z2 - z1 ** 2) / z2 - z1 + (y1 - y2) * c1 / b1
    # y0 = -(c1 * z1 + d1) / b1
    # y轴方向
    from sympy import Symbol, solve
    
    # 定义变量
    y = Symbol('y')
    z = Symbol('z')
    res = solve([a2 * (x1 - x0) + b2 * (y1 - y) + c2 * (z1 - z), a1 * x0 + b1 * y + c1 * z + d1], [y, z])
    print(res, type(res))
    y0 = res[y]
    z0 = res[z]
    del z, y
    print(869,y0, z0)
    a3 = x0 - x1
    # a3 = b1 * c2 - b2 * c1
    # b3 = a2 * c1 - a1 * c2
    # c3 = a1 * b2 - a2 * b1
    b3 = y0 - y1
    c3 = z0 - z1
    # y轴:(x-x0)/a3=(y-y0)/b3=(z-z0)/c3
    # xzh = ((x1, y1, z1), (a2, b2, c2))
    # yzh = ((x0, y0, z0), (a3, b3, c3))
    xzh = ((0, 0, 0), (1, 0, 0))
    yzh = ((0, 0, 0), (0, 0, 1))
    print(xzh)
    print(yzh)
    
    def juli_pointtoline(x1, y1, z1, zh):
        (x2, y2, z2), (a, b, c) = zh
        x = Symbol('x')
        y = Symbol('y')
        z = Symbol('z')
        res = {}
        if a == 0:
            a = 0.00001
        if b == 0:
            b = 0.00001
        if c == 0:
            c = 0.00001
        res = solve([a * (x - x1) + b * (y -
                                         y1) + c * (z - z1), (x - x2) / a - (y - y2) / b,
                     (x - x2) / a - (z - z2) / c], [x, y, z])
        x_j = res[x]
        y_j = res[y]
        z_j = res[z]
        # x = (a * x1 + (b ** 2 + c ** 2) / a * x2 + b * y1
        #      - b * y2 + c * z1 - c * z2) / (a + (b ** 2 + c ** 2) / a)
        # y = (b * (x1 - x2)) / a + y2
        # z = (c * (x1 - x2)) / a + z2
        juli = round(((x_j - x1) ** 2 + (y_j - y1) **
                      2 + (z_j - z1) ** 2) ** 0.5, 3)
        return float(juli)
    
    
    # print('juli_pointtoline', juli_pointtoline(0, 0, 0, ((1, 0, 0), (1, 0, 0))))
    
    
    def IsTrangleOrArea(x1, y1, x2, y2, x3, y3):
        return round(abs((x1 * (y2 - y3) + x2 * (y3 - y1) + x3 * (y1 - y2)) / 2.0), 3)
    
    
    def IsInside(x1, y1, x2, y2, x3, y3, x, y):
        # 三角形ABC的面积
        ABC = IsTrangleOrArea(x1, y1, x2, y2, x3, y3)
        if ABC:
            # 三角形PBC的面积
            PBC = IsTrangleOrArea(x, y, x2, y2, x3, y3)
    
            # 三角形ABC的面积
            PAC = IsTrangleOrArea(x1, y1, x, y, x3, y3)
    
            # 三角形ABC的面积
            PAB = IsTrangleOrArea(x1, y1, x2, y2, x, y)
    
            return (round(ABC, 3) == round(PBC + PAC + PAB, 3))
        else:
            return False
    
    
    ls = []
    # a, b, c, d = 0, 0, 1, 30
    arr1=arr[1:]
    arr1=[(item[0]+100,item[1],item[2],item[4])for item in arr1]
    for point in arr1:
        x4, y4, z4 = point[0], point[1], point[2]
        x5, y5, z5 = touying(a1, b1, c1, d1, x4, y4, z4)
        juli_x = juli_pointtoline(x5, y5, z5, xzh)
        juli_y = juli_pointtoline(x5, y5, z5, yzh)
        ls.append([juli_x, juli_y,point[0], point[1], point[2],point[3]])
    
    # with_goto = goto.with_goto
    # print(IsInside(0,0,1,1,2,2.1,0,0))
    
    print('945:',ls)
    ls=[[item[0],item[1],item[2],item[3],item[4],item[5]]for item in ls]
    import pandas as pd
    
    
    def plot_triangle(x1, y1, x2, y2, x3, y3, x4, y4):
        import matplotlib.pyplot as plt
        import numpy as np
        fig = plt.figure()
        # 将字体修改为 支持雅黑 ---支持中文
        plt.rcParams['font.sans-serif'] = 'SimHei'
        # 修改编码 让其支持负号
        plt.rcParams['axes.unicode_minus'] = False
        x_ls = [x1, x2, x3, x4]
        y_ls = [y1, y2, y3, y4]
        global df, df1
    
        # plt.scatter(df1.iloc[:,0],df1.iloc[:,1], s=50,
        #                         c='r',
        #                         marker='*',
        #                         alpha=0.5)
        # plt.scatter(x_ls, y_ls, marker='*', alpha=0.5)
        x = x_ls[:-1] + [x_ls[0]]
        y = y_ls[:-1] + [y_ls[0]]
        plt.plot(x, y, linewidth=1, color='red')
        x_two = [x3, x1]
        y_two = [y3, y1]
        plt.scatter(x4, y4, s=50,
                    c='black',
                    marker='*',
                    alpha=0.5)
        # plt.plot(x_two, y_two, linewidth=1, color='red')
        # plt.fill(x_ls, y_ls, facecolor='red', alpha=0.5)
        # fig.add_subplot(2, 1, 2)
    
        # fig.add_subplot(2, 2, 3)
        #
        # fig.add_subplot(2, 2, 4)
    
        # 图片保存
        # plt.savefig('./子图绘制.png')
    
        # 3、展示
        plt.show()
    
    
    def waibaoluo(ls):
        global df1
        df = pd.DataFrame(ls)
        # print(df)
        # lenth = ls.__len__()
        df = df.sort_values(by=0)
        df = df.reset_index(drop=True)
        # print(df)
        df['x'] = df.iloc[:, 0]
        df['y'] = df.iloc[:, 1]
        df['rx'] = df.iloc[:, 2]
        df['ry'] = df.iloc[:, 3]
        df['rz'] = df.iloc[:, 4]
        del df[0], df[1],df[2],df[3],df[4]
        print('1010df:',df)
    
        xmin = df.iloc[0].x
        ymin = df.iloc[0].y
        ox=df.iloc[0].rx
        oy = df.iloc[0].ry
        oz = df.iloc[0].rz
        df = df.drop(index=0)
        df['xielv'] = (df['y'] - ymin) / (df['x'] - xmin)
        df['juli'] = (df['x'] - xmin) ** 2 + (df['y'] - ymin) ** 2
        df = df.sort_values(by=['xielv', 'juli'], ascending=[False, False]).reset_index(drop=True)
        # print(df)
        # df.to_csv('data/df.csv')
        # df1=pd.read_csv('data/df.csv')
        A = xmin, ymin
        B = df.iloc[0].x, df.iloc[0].y
        C = df.iloc[1].x, df.iloc[1].y
    
        ls_new = []
        ls_new.append(A)
        ls_new.append(B)
    
        for i in range(2, len(df)):
            condition = False
            D = df.iloc[i].x, df.iloc[i].y
            if not IsInside(A[0], A[1], B[0], B[1], D[0], D[1], C[0], C[1]):
                # plot_triangle(A[0], A[1], B[0], B[1], D[0], D[1], C[0], C[1])
                ls_new.append(tuple(C))
                C = df.iloc[i].x,df.iloc[i].y
                condition = True
            else:
                # plot_triangle(A[0], A[1], B[0], B[1], D[0], D[1], C[0], C[1])
                ls_it = []
                df.iloc[i - 1].x,df.iloc[i - 1].y = -999, -999
                if len(ls_new) > 2:
                    ls_it = list(range(2, len(ls_new)))
                    if ls_it != None:
                        ls_it.reverse()
    
                for j in ls_it:
                    B = ls_new[j]
                    print('B:', B)
                    for k in range(j, len(ls_new)):
                        C = ls_new[k]
                        if IsInside(A[0], A[1], B[0], B[1], D[0], D[1], C[0], C[1]):
                            # plot_triangle(A[0], A[1], B[0], B[1], D[0], D[1], C[0], C[1])
                            # if C in ls_new:
                            # print(C)
                            # print(tuple(C))
                            ls_new.remove(tuple(C))
                            cond = (df.iloc[:]['x'] == C[0]) & (df.iloc[:]['y'] == C[1])
                            # print(cond)
                            df_con = df[cond]
                            # df_con.loc['x']=999
                if i < len(ls):
                    C = df.iloc[i].x, df.iloc[i].y
                continue
            B = df.iloc[i - 1].x, df.iloc[i - 1].y
            if i + 1 < len(ls) and not condition:
                C = df.iloc[i + 1].x, df.iloc[i + 1].y
    
        print(df)
        is999 = df['x'] == -999
        cond999 = []
    
        for i in range(len(df)):
            if is999[i]:
                cond999.append(i)
    
        print(cond999)
        df = df.drop(index=cond999)
        df.index = [index for index in range(1, len(df) + 1)]
        bool_arr = df['x'] == df['x'].max()
        bool_arr = list(bool_arr)
        index = bool_arr.index(True)
        df_front = df.iloc[:index + 1]
        df_rear = df.iloc[index:]
        df2 = pd.DataFrame([[xmin, ymin, 0, 0,ox,oy,oz]],
        columns=['x', 'y', 'xielv', 'juli','rx','ry','rz'])
        print('line1089:',df2)
        print(df2.iloc[0])
        df = pd.concat([df2, df, df2]).reset_index(drop=True)
        print('line1092',df)
        return df
    
    
    # def waibaoluo_reverse(ls):
    #     global df1
    #     df = pd.DataFrame(ls)
    #     # print(df)
    #     # lenth = ls.__len__()
    #     df = df.sort_values(by=0)
    #     df = df.reset_index(drop=True)
    #     # print(df)
    #     df['x'] = df.iloc[:, 0]
    #     df['y'] = df.iloc[:, 1]
    #     del df[0], df[1]
    #     print(df)
    #
    #
    #     xmin = df.iloc[0, 0]
    #     ymin = df.iloc[0, 1]
    #     df = df.drop(index=0)
    #     df['xielv'] = (df['y'] - ymin)/(df['x'] - xmin)
    #     df['juli'] = (df['x'] - xmin) ** 2 + (df['y'] - ymin) ** 2
    #     df = df.sort_values(by=['xielv', 'juli'], ascending=[True, False]).reset_index(drop=True)
    #     print(df)
    #     df1=df.copy()
    #     A = xmin, ymin
    #     B = df.iloc[0][0], df.iloc[0][1]
    #     C = df.iloc[1][0], df.iloc[1][1]
    #
    #     ls_new = []
    #     ls_new.append(A)
    #     ls_new.append(B)
    #
    #     for i in range(2, len(df)):
    #         condition=False
    #         D = df.iloc[i][0], df.iloc[i][1]
    #         if not IsInside(A[0], A[1], B[0], B[1], D[0], D[1], C[0], C[1]):
    #             plot_triangle(A[0], A[1], B[0], B[1], D[0], D[1], C[0], C[1])
    #             ls_new.append(tuple(C))
    #             C=df.iloc[i][:2]
    #             condition=True
    #         else:
    #             xy=df[(df['x']==C[0])&(df['y']==C[1])]
    #             xy['x'],xy['y']=(-999,-999)
    #             if tuple(C) in ls:
    #                 C=tuple(C)
    #                 ls.remove(C)
    #             plot_triangle(A[0], A[1], B[0], B[1], D[0], D[1], C[0], C[1])
    #             ls_it = []
    #             df.iloc[i-1][:2]=[-999,-999]
    #             if len(ls_new) > 2:
    #                 ls_it = list(range(2, len(ls_new)))
    #                 if ls_it != None:
    #                     ls_it.reverse()
    #
    #             for j in ls_it:
    #                 B = ls_new[j]
    #                 print('B:',B)
    #                 for k in range(j, len(ls_new)):
    #                     C = ls_new[k]
    #                     if IsInside(A[0], A[1], B[0], B[1], D[0], D[1], C[0], C[1]):
    #                         plot_triangle(A[0], A[1], B[0], B[1], D[0], D[1], C[0], C[1])
    #                         # if C in ls_new:
    #                         # print(C)
    #                         # print(tuple(C))
    #                         ls_new.remove(tuple(C))
    #                         cond=(df.iloc[:]['x']==C[0])&(df.iloc[:]['y']==C[1])
    #                         # print(cond)
    #                         df_con=df[cond]
    #                         # df_con.loc['x']=999
    #             if i < len(ls):
    #                 C = df.iloc[i][0], df.iloc[i][1]
    #             continue
    #         B = df.iloc[i - 1][0], df.iloc[i - 1][1]
    #         if i + 1 < len(ls) and not condition:
    #             C = df.iloc[i + 1][0], df.iloc[i + 1][1]
    #             print(df)
    #
    #
    #     print(df)
    #     is999 = df['x'] == -999
    #     cond999 = []
    #
    #     for i in range(len(df)):
    #         if is999[i]:
    #             cond999.append(i)
    #
    #     print(cond999)
    #     df = df.drop(index=cond999)
    #     df.index = [index for index in range(1, len(df) + 1)]
    #     bool_arr = df['x'] == df['x'].max()
    #     bool_arr = list(bool_arr)
    #     index = bool_arr.index(True)
    #     df_front = df.iloc[:index + 1]
    #     df_rear = df.iloc[index:]
    #     df2 = pd.DataFrame([[xmin, ymin, 0, 0]], columns=['x', 'y', '1', '2'])
    #     print(df2)
    #     print(df2.iloc[0])
    #     df = pd.concat([df2, df, df2]).reset_index(drop=True)
    #     return df
    #
    #
    # # df=waibaoluo_reverse(ls)
    # df = pd.DataFrame(ls)
    # # print(df)
    # # lenth = ls.__len__()
    # df = df.sort_values(by=0)
    # df = df.reset_index(drop=True)
    # # print(df)
    # df['x'] = df.iloc[:, 0]
    # df['y'] = df.iloc[:, 1]
    # del df[0], df[1]
    # print(df)
    #
    #
    # xmin = df.iloc[0, 0]
    # ymin = df.iloc[0, 1]
    # df = df.drop(index=0)
    # df['xielv'] = (df['y'] - ymin)/(df['x'] - xmin)
    # df['juli'] = (df['x'] - xmin) ** 2 + (df['y'] - ymin) ** 2
    # df = df.sort_values(by=['xielv', 'juli'], ascending=[True, False]).reset_index(drop=True)
    # print(df)
    # df1=df.copy()
    # print(df)
    # def orientation(p,q,r):
    #     val = (q[1] - p[1]) * (r[0] - q[0]) - (q[0] - p[0]) * (r[1] - q[1])
    #
    #     if (val == 0):
    #         return 0 # colinear
    #     if val > 0:
    #         return 1
    #     else:
    #         return 2
    #
    #
    # }
    # x_ls=df['x']
    # y_ls=df['y']
    def duplicated(i, j, k, l):
        ls = i, j, k, l
        c1 = 0
        while (c1 < ls.__len__() - 1):
            c2 = c1 + 1
            while (c2 < ls.__len__()):
                if ls[c1] == ls[c2]:
                    return True
                c2 += 1
            c1 += 1
        return False
    
    
    # def zuhe(l):
    #     ls = []
    #     for i in range(l):
    #         for j in range(l):
    #             for k in range(l):
    #                 for l in range(l):
    #                     if duplicated(i, j, k, l):
    #                         continue
    #                     ls.append((i, j, k, l))
    
    
    def test(ls):
        import matplotlib.pyplot as plt
        import numpy as np
        ijl_ls = []
        global df1
        df1 = pd.DataFrame(list(ls))
        # print(df)
        # lenth = ls.__len__()
        df1 = df1.sort_values(by=0)
        df1 = df1.reset_index(drop=True)
        # print(df)
        df1['x'] = df1.iloc[:, 0]
        df1['y'] = df1.iloc[:, 1]
        print('1268:',df1)
        df1['type'] = df1.iloc[:, 5]
    
        del df1[0], df1[1],df1[5]
    
        while True:
            b = False
            for i in range(len(ls)):
                if b == True: break
                for j in range(len(ls)):
                    if b == True: break
                    for k in range(len(ls)):
                        if b == True: break
                        for l in range(len(ls)):
                            # ijk = [i, j, k]
                            # ijk.sort()
                            # ijk.append(l)
                            # if ijk not in ijl_ls:
                            #     ijl_ls.append(ijk)
                            # else:
                            #     continue
                            x1, y1 = ls[i][0],ls[i][1]
                            x2, y2 = ls[j][0],ls[j][1]
                            x3, y3 = ls[k][0],ls[k][1]
                            x4, y4 = ls[l][0],ls[l][1]
                            # print(x1, y1, x2, y2, x3, y3, x4, y4)
                            if not duplicated(i, j, k, l):
                                if IsInside(x1, y1, x2, y2, x3, y3, x4, y4):
                                    x_ls = [x1, x2, x3, x4]
                                    y_ls = [y1, y2, y3, y4]
                                    # plt.scatter(x_ls, y_ls,
                                    #
                                    #             marker='.',
                                    #             alpha=0.5)
                                    # x = x_ls[:-1] + [x_ls[0]]
                                    # y = y_ls[:-1] + [y_ls[0]]
                                    # plt.plot(x, y, linewidth=1, color='red')
                                    # # plt.fill(x_ls, y_ls, facecolor='red', alpha=0.5)
                                    # fig.add_subplot(2, 1, 2)
                                    #
                                    # # fig.add_subplot(2, 2, 3)
                                    # #
                                    # # fig.add_subplot(2, 2, 4)
                                    #
                                    # # 图片保存
                                    # # plt.savefig('./子图绘制.png')
                                    #
                                    # # 3、展示
                                    # plt.show()
                                    # plot_triangle(x1, y1, x2, y2, x3, y3, x4, y4)
                                    del ls[l]
                                    # print(i,j,k,l)
                                    b = True
                                    break
            if b == False:
                break
    
    
    print('1314ls::', ls)
    # print(type(ls[0][0]))
    ls = [(float(xy[0]), float(xy[1]),xy[2],xy[3],xy[4],xy[5]) for xy in ls]
    test(ls)
    print('1318ls:', ls)
    df = waibaoluo(ls)
    # x_ls = [xy[0] for xy in ls_new]
    # y_ls = [xy[1] for xy in ls_new]
    print(1332,df)
    df['y']-=100
    df['tmp']=df['x']
    df['x']=df['y']
    df['y']=df['tmp']
    del df['tmp']
    print('line1329',df)
    df1['tmp']=df1['x']
    df1['x']=df1['y']
    df1['y']=df1['tmp']
    del df1['tmp']
    df1['x']-=100
    print('line1343df1:',df1)
    df.to_csv('./data/大坝图.csv')
    df.to_json('data/大坝图xz.json')
    # 散点图
    # 直角坐标系 中---  点 ---横纵坐标  ---(x1,y1) (x2,y2) ....
    
    import matplotlib.pyplot as plt
    import numpy as np
    
    # # 1、创建画布
    # plt.figure()
    #
    # # 2、绘图
    # # 需要准备两个长度相同的数组
    # x = np.array([1, 2, 3, 4, 5])
    # y = np.array([18, 20, 21, 15, 13])
    #
    # # 绘制散点图
    # # s 表示点的大小--可以指定数组或者 具体的点的大小
    # # c 表示点的颜色 --可以指定数组或者具体的一个颜色
    # # marker  点的样式
    # # alpha  透明度 --[0,1]
    # plt.scatter(x, y, s=[30, 20, 10, 5, 50],
    #             c=['r', 'g', 'b', 'black', 'c'],
    #             marker='*',
    #             alpha=0.5)
    # # 3、展示
    # plt.show()
    
    # 散点图 ---应用场景:
    #  可以用来查看 发展趋势
    #  可以用来查看数据集中数据的分布状态
    
    # 如何增加子图  ???
    # 1、创建画布  ---返回画布对象
    fig = plt.figure(figsize=(24,20))
    # 将字体修改为 支持雅黑 ---支持中文
    plt.rcParams['font.sans-serif'] = 'SimHei'
    # 修改编码 让其支持负号
    plt.rcParams['axes.unicode_minus'] = False
    # 调整子图的间距
    # wspace=None, 具体的数值 ---便是宽度间距为wspace倍的子图宽度
    # hspace=None  具体的数值 ---表示的高度间距为 hspace倍的子图高度
    # plt.subplots_adjust(hspace=0.3)
    # 增加子图
    # 参数1 绘制的子图的 行数
    # 参数2 绘制的子图的 列数
    # 参数3 绘制的子图的 编号
    # fig.add_subplot(2, 1, 1)
    # 2、绘图
    # 需要准备两个长度相同的数组
    # x = np.array([1, 2, 3, 4, 5])
    # y = np.array([18, 20, 21, 15, 13])
    
    # 绘制散点图
    # s 表示点的大小--可以指定数组或者 具体的点的大小
    # c 表示点的颜色 --可以指定数组或者具体的一个颜色
    # marker  点的样式
    # alpha  透明度 --[0,1]
    # plt.scatter(x_ls, y_ls,
    #
    #             marker='.',
    #             alpha=0.5)
    # for i in range(len(x_ls)):
    #     for j in range(len(y_ls)):
    #         x = x_ls[i], x_ls[j]
    #         y = y_ls[i], y_ls[j]
    #         plt.plot(x, y, linewidth=1, color='red')
    plt.plot(df['x'], df['y'], linewidth=1, color='red')
    plt.fill(df['x'], df['y'], facecolor='red', alpha=0.5)
    print(1398,df1)
    
    plt.scatter(df1['x'], df1['y'], s=50,
                c='black',
                marker='*',
                alpha=0.5)
    from matplotlib import pyplot as plt
    import numpy as np
    # fig = plt.figure()
    ax = fig.add_subplot(111)
    # A = -0.75, -0.25, 0, 0.25, 0.5, 0.75, 1.0
    # B = 0.73, 0.97, 1.0, 0.97, 0.88, 0.73, 0.54
    # plt.plot(A,B)# annotations at the side (ordered by B values)
    #
    x0,x1=ax.get_xlim()
    y0,y1=ax.get_ylim()
    for ii, ind in enumerate(np.argsort(df1['type'])):
        x = df1.iloc[ind].x
        y = df1.iloc[ind].y
        xPos = x1 + .02 * (x1 - x0)
        yPos = y0 + ii * (y1 - y0)/(len(df1['type']) - 1)
        ax.annotate('',#label,
       xy=(x, y),
       xycoords='data',
       xytext=(xPos, yPos),
       textcoords='data',
       arrowprops=dict(
       connectionstyle="arc3,rad=0.",
       shrinkA=0, shrinkB=10,
       arrowstyle= '-|>',
       ls= '-', linewidth=2
       ),
       va='bottom',
       ha='left',
       zorder=19
       )
        ax.text(xPos + .01 * (x1 - x0),
                yPos,
                '{}:({:.2f}, {:.2f})'.format(df1.iloc[ind].type,x,y),
                transform=ax.transData,
                va='center')
    plt.grid()
    plt.xlabel('坝横')
    plt.ylabel('高程')
    # fig.add_subplot(2, 1, 2)
    
    # fig.add_subplot(2, 2, 3)
    #
    # fig.add_subplot(2, 2, 4)
    
    # 图片保存
    plt.savefig('./大坝图11.png')
    
    # 3、展示
    plt.show()
    # input('按回车以继续')
    点赞 评论 复制链接分享
  • jiangjinghua 江jh 4月前

     

    报错信息:

    Traceback (most recent call last):
      File "E:/Users/jjh/大坝图/dabatu11.py", line 1329, in <module>
        test(ls)
      File "E:/Users/jjh/大坝图/dabatu11.py", line 1268, in test
        print('1268:',df1)
      File "D:\Users\asus\AppData\Local\Programs\Python\Python37\lib\site-packages\pandas\core\frame.py", line 751, in __repr__
        show_dimensions=show_dimensions,
      File "D:\Users\asus\AppData\Local\Programs\Python\Python37\lib\site-packages\pandas\core\frame.py", line 883, in to_string
        return formatter.to_string(buf=buf, encoding=encoding)
      File "D:\Users\asus\AppData\Local\Programs\Python\Python37\lib\site-packages\pandas\io\formats\format.py", line 921, in to_string
        return self.get_result(buf=buf, encoding=encoding)
      File "D:\Users\asus\AppData\Local\Programs\Python\Python37\lib\site-packages\pandas\io\formats\format.py", line 520, in get_result
        self.write_result(buf=f)
      File "D:\Users\asus\AppData\Local\Programs\Python\Python37\lib\site-packages\pandas\io\formats\format.py", line 841, in write_result
        text = self._join_multiline(*strcols)
      File "D:\Users\asus\AppData\Local\Programs\Python\Python37\lib\site-packages\pandas\io\formats\format.py", line 883, in _join_multiline
        lwidth -= np.array([self.adj.len(x) for x in idx]).max() + adjoin_width
      File "D:\Users\asus\AppData\Local\Programs\Python\Python37\lib\site-packages\numpy\core\_methods.py", line 39, in _amax
        return umr_maximum(a, axis, None, out, keepdims, initial, where)
    TypeError: int() argument must be a string, a bytes-like object or a number, not '_NoValueType'

    Process finished with exit code 1

    点赞 评论 复制链接分享
  • jiangjinghua 江jh 4月前

    回去我把代码发一下

    点赞 评论 复制链接分享
  • jiangjinghua 江jh 4月前

    输出dataframe对象的时候报错

    点赞 评论 复制链接分享

相关推荐