第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如何提取 melt 函數(shù)的列名?Python

如何提取 melt 函數(shù)的列名?Python

UYOU 2023-01-04 16:16:13
我有一個包含以下列的數(shù)據(jù)集。data.columns[1:]Index(['Fraud (i.e. fabricated or falsified results)',       'Pressure to publish for career advancement',       'Insufficient oversight/mentoring by lab principal investigator (e.g. reviewing raw data)',       'Insufficient peer review of research',       'Selective reporting of results',       'Original findings not robust enough because not replicated enough in the lab publishing the work',       'Original findings obtained with low statistical power/poor statistical analysis',       'Mistakes or inadequate expertise in reproduction efforts',       'Raw data not available from original lab',       'Protocols, computer code or reagent information insufficient or not available from original lab',       'Methods need 'green fingers' – particular technical expertise that is difficult for others to reproduce',       'Variability of standard reagents', 'Poor experimental design',       'Bad luck'],      dtype='object')而且我想使用列來做融化功能,所以我做了下面的代碼。data_melt = pd.melt(data, id_vars =['respid'], value_vars =['Fraud (i.e. fabricated or falsified results)', 'Pressure to publish for career advancement', 'Insufficient oversight/mentoring by lab principal investigator (e.g. reviewing raw data)', 'Insufficient peer review of research', 'Selective reporting of results', 'Original findings not robust enough because not replicated enough in the lab publishing the work', 'Original findings obtained with low statistical power/poor statistical analysis', 'Mistakes or inadequate expertise in reproduction efforts', 'Raw data not available from original lab',基本上,我只是將列名粘貼到 value_vars 中。我的問題是是否可以編寫代碼來實現(xiàn)相同的目標?例如,只需編寫如下代碼。(我知道這是錯誤的。)data_melt = pd.melt(data, id_vars =['respid'], value_vars = data.columns(), ,var_name = 'factor', value_name = 'rate')謝謝!
查看完整描述

1 回答

?
慕沐林林

TA貢獻2016條經(jīng)驗 獲得超9個贊

這是一個解決方案:


# Create a dummy dataframe with columns similar to yours. 

df = pd.DataFrame({"respid": range(5),

                   "Fraud (i.e. fabricated or falsified results)": range(5,10), 

                   'Pressure to publish for career advancement': range(10, 15), 

                   'Insufficient oversight/mentoring by lab principal investigator (e.g. reviewing raw data)': range(15,20), 

                   'Insufficient peer review of research': range(20,25)

                  })


pd.melt(df, id_vars =['respid'], value_vars=set(df.columns).difference(["respid"]))

結(jié)果是:


    respid                                           variable  value

0        0       Fraud (i.e. fabricated or falsified results)      5

1        1       Fraud (i.e. fabricated or falsified results)      6

2        2       Fraud (i.e. fabricated or falsified results)      7

3        3       Fraud (i.e. fabricated or falsified results)      8

4        4       Fraud (i.e. fabricated or falsified results)      9

5        0               Insufficient peer review of research     20

6        1               Insufficient peer review of research     21

7        2               Insufficient peer review of research     22

8        3               Insufficient peer review of research     23

...


查看完整回答
反對 回復(fù) 2023-01-04
  • 1 回答
  • 0 關(guān)注
  • 130 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號