对于每个基因,我想绘制时间(x轴)对基因表达(y轴)的影响。
我的代码引发了ValueError: DataFrame constructor not properly called!
错误。
import plotly.express as px
import numpy as np
import pandas as pd
for time, gene_expr in df5.iloc[:, 1:-1].iterrows():
X = time
y = gene_expr
fig = px.scatter(X, y)
fig.show()
追溯:
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
<ipython-input-424-e9af712893e6> in <module>()
4 y = gene_expr
5
----> 6 fig = px.scatter(X, y)
7 fig.show()
3 frames
/usr/local/lib/python3.7/dist-packages/plotly/express/_chart_types.py in scatter(data_frame, x, y, color, symbol, size, hover_name, hover_data, custom_data, text, facet_row, facet_col, facet_col_wrap, facet_row_spacing, facet_col_spacing, error_x, error_x_minus, error_y, error_y_minus, animation_frame, animation_group, category_orders, labels, orientation, color_discrete_sequence, color_discrete_map, color_continuous_scale, range_color, color_continuous_midpoint, symbol_sequence, symbol_map, opacity, size_max, marginal_x, marginal_y, trendline, trendline_options, trendline_color_override, trendline_scope, log_x, log_y, range_x, range_y, render_mode, title, template, width, height)
64 mark in 2D space.
65 """
---> 66 return make_figure(args=locals(), constructor=go.Scatter)
67
68
/usr/local/lib/python3.7/dist-packages/plotly/express/_core.py in make_figure(args, constructor, trace_patch, layout_patch)
1943 apply_default_cascade(args)
1944
-> 1945 args = build_dataframe(args, constructor)
1946 if constructor in [go.Treemap, go.Sunburst, go.Icicle] and args["path"] is not None:
1947 args = process_dataframe_hierarchy(args)
/usr/local/lib/python3.7/dist-packages/plotly/express/_core.py in build_dataframe(args, constructor)
1304 df_provided = args["data_frame"] is not None
1305 if df_provided and not isinstance(args["data_frame"], pd.DataFrame):
-> 1306 args["data_frame"] = pd.DataFrame(args["data_frame"])
1307 df_input = args["data_frame"]
1308
/usr/local/lib/python3.7/dist-packages/pandas/core/frame.py in __init__(self, data, index, columns, dtype, copy)
728 else:
729 if index is None or columns is None:
--> 730 raise ValueError("DataFrame constructor not properly called!")
731
732 # Argument 1 to "ensure_index" has incompatible type "Collection[Any]";
ValueError: DataFrame constructor not properly called!
数据:
df5.head().to_dict()
{'DNAJA1': {'0': 0.28248390645176796,
'12': 0.27744322221439516,
'24': 0.210254923999168,
'4': 0.25179129535390465,
'8': 0.23958153803449567},
'DNAJA1P5': {'0': -0.2080266957602313,
'12': -0.19722801757776928,
'24': -0.1976431590905783,
'4': -0.20053252198361712,
'8': -0.2036891696122125},
'DNAJA2': {'0': 0.2379156190731321,
'12': 0.23129783609535023,
'24': 0.20515225879608529,
'4': 0.21167004692557853,
'8': 0.22217035173976502},
'DNAJA3': {'0': 0.14072466843555423,
'12': 0.12502300219684245,
'24': 0.14012001787306544,
'4': 0.1526473568816046,
'8': 0.12756243532358302},
'DNAJA4': {'0': 0.29363403599517873,
'12': 0.2199610571535649,
'24': 0.21450642787801127,
'4': 0.2863189438304104,
'8': 0.22237180092783923},
'DNAJB1': {'0': 0.3948121317283425,
'12': 0.3608993750139941,
'24': 0.3311254737056284,
'4': 0.3981327559482513,
'8': 0.3319362201574015},
'DNAJB11': {'0': 0.2746271580199511,
'12': 0.23630738713618987,
'24': 0.22299890869123462,
'4': 0.24300028615442973,
'8': 0.2382232952434325},
'DNAJB12': {'0': 0.10668014577426282,
'12': 0.11955750186231344,
'24': 0.12738441668520886,
'4': 0.12070656206120234,
'8': 0.11469633018832656},
'DNAJB13': {'0': -0.07673116489135769,
'12': -0.06776710496304854,
'24': -0.07153667570066105,
'4': -0.06691126916859379,
'8': -0.07310350056725066},
'DNAJB14': {'0': 0.2936152967643217,
'12': 0.30721637266817337,
'24': 0.2752172143325089,
'4': 0.28537539621170677,
'8': 0.2847856843270891},
'DNAJB2': {'0': 0.1581524535439132,
'12': 0.15176006759808186,
'24': 0.14005726324108353,
'4': 0.16744525625230677,
'8': 0.14085238694516192},
'DNAJB3': {'0': -0.09587483337552667,
'12': -0.09817644148708737,
'24': -0.09660994242851631,
'4': -0.08518473151331872,
'8': -0.10146894931303332},
'DNAJB4': {'0': 0.07768482492238449,
'12': 0.017092721241614726,
'24': -0.01615829598116708,
'4': 0.020593555517848337,
'8': -0.004092727323577966},
'DNAJB5': {'0': 0.09496018939632274,
'12': 0.09235963667312883,
'24': 0.10859047142465117,
'4': 0.11145101928004025,
'8': 0.09014175789905482},
'DNAJB6 /// TMEM135': {'0': 0.30131649339447103,
'12': 0.28354614480145346,
'24': 0.27395808285292367,
'4': 0.2949284643966144,
'8': 0.2794865791356734},
'DNAJB7': {'0': -0.15771205782877812,
'12': -0.14511310398241917,
'24': -0.1555102987841566,
'4': -0.1443977313282421,
'8': -0.15281879296022327},
'DNAJB8': {'0': -0.05820495004065927,
'12': -0.04784161289502813,
'24': -0.049103502142104925,
'4': -0.049599985194195624,
'8': -0.06345844493362643},
'DNAJB9': {'0': 0.11076998890482295,
'12': 0.06169995333733465,
'24': 0.05327189778896728,
'4': 0.07866774006161506,
'8': 0.054673294559794514},
'DNAJC1': {'0': 0.24892722200000175,
'12': 0.24941676796653142,
'24': 0.24834878985541864,
'4': 0.23839909816627536,
'8': 0.2457747521222172},
'DNAJC10': {'0': 0.2552488374526568,
'12': 0.23718885573814158,
'24': 0.219399461349515,
'4': 0.25279546962976474,
'8': 0.2313752090822519},
'DNAJC11': {'0': 0.10008360015453403,
'12': 0.09051095629609844,
'24': 0.08314056952230306,
'4': 0.10190650783898647,
'8': 0.08229407961363017},
'DNAJC12': {'0': -0.12299257208661085,
'12': -0.1141270169596548,
'24': -0.13300032732527073,
'4': -0.13215534856752542,
'8': -0.1269886655735006},
'DNAJC13': {'0': 0.4009152082570292,
'12': 0.43945616890620476,
'24': 0.406718584282217,
'4': 0.4051887086934543,
'8': 0.4207699468459298},
'DNAJC14': {'0': 0.2255444383216058,
'12': 0.2343653660720247,
'24': 0.2246018336027369,
'4': 0.22905481299223704,
'8': 0.22228815371920396},
'DNAJC15': {'0': 0.25789169794229455,
'12': 0.2406210529534205,
'24': 0.22347959865906092,
'4': 0.22312009403152122,
'8': 0.22912018863353348},
'DNAJC16': {'0': 0.25118250606032994,
'12': 0.2634603140695134,
'24': 0.2559437693580005,
'4': 0.260663050530101,
'8': 0.25672778315798805},
'DNAJC17': {'0': 0.0718240184764887,
'12': 0.08705114604826444,
'24': 0.07478605493065499,
'4': 0.0867030049108327,
'8': 0.07226672139164557},
'DNAJC18': {'0': 0.05301961450370261,
'12': 0.04754701545460298,
'24': 0.04744710465261325,
'4': 0.058410734627379245,
'8': 0.04612151982443032},
'DNAJC19': {'0': -0.061318907045887217,
'12': -0.06522383392518652,
'24': -0.07428845844165784,
'4': -0.07689535420225665,
'8': -0.07132412412619679},
'DNAJC2': {'0': 0.12354944077460604,
'12': 0.10590867281952658,
'24': 0.08647106591019343,
'4': 0.11280280873592663,
'8': 0.09861702152191035},
'DNAJC21': {'0': 0.18568509930510457,
'12': 0.16206451389465568,
'24': 0.13974449617707058,
'4': 0.1642464451002627,
'8': 0.1601371719124281},
'DNAJC22': {'0': -0.09326088886326482,
'12': -0.09994315166353215,
'24': -0.09818616566701992,
'4': -0.0766139542789032,
'8': -0.09474493076293106},
'DNAJC24': {'0': -0.024407871322284516,
'12': -0.04388395219646757,
'24': -0.030418881816888975,
'4': -0.03884605873284513,
'8': -0.04057519700577427},
'DNAJC25 /// DNAJC25-GNG10 /// GNG10': {'0': 0.18900015728770594,
'12': 0.1924709267155032,
'24': 0.1855722328342354,
'4': 0.18293809001992412,
'8': 0.17782253125321112},
'DNAJC27': {'0': 0.031979181807859955,
'12': 0.031014849632422552,
'24': 0.03738291752852443,
'4': 0.05264384837943797,
'8': 0.01639331282320123},
'DNAJC28': {'0': -0.10603389682143655,
'12': -0.10738830197430897,
'24': -0.11228995887813542,
'4': -0.1091487503462486,
'8': -0.12087183521953099},
'DNAJC3': {'0': 0.30260069114488775,
'12': 0.3250607363561909,
'24': 0.296968150791487,
'4': 0.2999460613167164,
'8': 0.3223833673779394},
'DNAJC30': {'0': 0.11388797858763917,
'12': 0.11229754447748205,
'24': 0.11379897713291527,
'4': 0.13114878202076288,
'8': 0.11799998627920205},
'DNAJC4 /// NUDT22': {'0': 0.24319510455934645,
'12': 0.27248047790015295,
'24': 0.2758415067986132,
'4': 0.2617636798697484,
'8': 0.2612483452622727},
'DNAJC5': {'0': 0.29256319288876087,
'12': 0.3284481866393536,
'24': 0.3097473292260611,
'4': 0.2991498817082909,
'8': 0.3118310482972686},
'DNAJC5B': {'0': -0.16513673294958436,
'12': -0.14577354129936956,
'24': -0.16602256134508964,
'4': -0.15831273634383858,
'8': -0.14704570894539276},
'DNAJC5G': {'0': -0.12154026872582889,
'12': -0.10829345557004925,
'24': -0.1128175514728689,
'4': -0.12706121166279596,
'8': -0.11547448664939705},
'DNAJC6': {'0': 0.013532483149184604,
'12': 0.016620550092782228,
'24': 0.011437913693540098,
'4': 0.015691143400912946,
'8': 0.011508823424590173},
'DNAJC7': {'0': 0.21805318734860135,
'12': 0.21928981693914756,
'24': 0.19266797382682654,
'4': 0.20586403937384182,
'8': 0.20525988410009127},
'DNAJC8': {'0': 0.1333821893656816,
'12': 0.14559322801116542,
'24': 0.10962743627286925,
'4': 0.1263955617218009,
'8': 0.11561971140994581},
'DNAJC9': {'0': 0.11205541676885071,
'12': 0.12045170255898871,
'24': 0.10622530623273815,
'4': 0.12991396178392187,
'8': 0.10520854728987451},
'LOC646358': {'0': 0.2368501920161727,
'12': 0.23935130874144087,
'24': 0.1927312962920997,
'4': 0.2082556333663144,
'8': 0.24129365615652498},
'ST13': {'0': 0.3904955795353276,
'12': 0.3429657340591041,
'24': 0.35263630061055307,
'4': 0.3832450736771604,
'8': 0.36547818653640995},
'ST13P4': {'0': 0.2125373177633469,
'12': 0.1844503555760748,
'24': 0.1844713371907022,
'4': 0.20655218905005068,
'8': 0.20207292104855787},
'ST13P5': {'0': 0.2388445698279386,
'12': 0.202381644929025,
'24': 0.20119515611287567,
'4': 0.22513288946386512,
'8': 0.223608506831124},
'VEGFA': {'0': 0.19732697850691847,
'12': 0.176210462112851,
'24': 0.17134417427533616,
'4': 0.17708075993852013,
'8': 0.16899091572086322},
'VEGFB': {'0': 0.1424721668873727,
'12': 0.13628100283545955,
'24': 0.14628256064354891,
'4': 0.17019608917147688,
'8': 0.13664990684590392},
'VEGFC': {'0': 0.0094810175674546,
'12': 0.021314980865977315,
'24': 0.027110162884579722,
'4': 0.016743433302740356,
'8': 0.006834653321976023},
'survival_info': {'0': '0h', '12': '12h', '24': '24h', '4': '4h', '8': '8h'}}
版本:
Python 3.7.13 plotly 5.9.0 Pandas 1.3.5
1条答案
按热度按时间tzcvj98z1#
正如@r-beginners所写的,pd.Dataframe.iterrows()返回一个元组
(row_index, row)
。在您的代码中,索引存储在X变量中,因此它只是一个整数,这会导致错误。我修改了你的代码来从iterrows中获取行信息:
我不确定,如果你真的想5个单独的散点图打印出来,虽然?