如何合并数据帧的行

问题描述 投票:0回答:1

我尝试使用表格从pdf中获取表格,并得到了这样的数据框

Crop(Varieties) Crop Specific Advisory 0 NaN Irrigate the crop if there is no sufficient mo... 1 NaN Borer spray insecticide like Carbaryl 50 WP @ ... 2 NaN 250ml/acre. If the attack of Fall Army worm is... 3 NaN for effective control of this insects or use p... 4 MAIZE म ा के खेत म पया नमी न होने पर फसल की िसंचाई ... 5 NaN िलए काब रल 50 डूपी @ 1 िकलो ाम / एकड़ की दर स... 6 NaN िमली / एकड़ दर से िछड़काव कर। यिद फ़ॉल आम कीड... 7 NaN भावी िनयं ण के िलए नीिमसाईड का िछड़काव कर या फ... 8 NaN Irrigate the crop if there is no sufficient mo... 9 NaN cutworm apply Carbaryl 50% WP @ 800g in 800 li... 10 NaN 76% EC@ 112-150ml in 200-400 liters of water/a... 11 NaN apply Chlorpyriphos 20% EC @ 3- 4 ml/kg seed a... 12 WHEAT गें की फसल म पया नमी न होने पर फसल की िसंचाई... 13 NaN िलए काब रल 50% WP @ 800 ाम को 800 लीटर पानी / ... 14 NaN @ 112-150 िम.ली. को 200-400 लीटर पानी / एकड़ क... 15 NaN दीमक को िनयंि त करने के िलए ोरपायरीफॉस 20% ईसी... 16 NaN म िछड़काव कर। 17 NaN Farmers are advised to apply N.P.V @ 250 L.E p... 18 NaN at the time of grain formation in pigeonpea/gr... 19 BENGAL cut worm then apply chlorpyriphos 20 EC @ 2 ml... 20 GRAM/ िकसानो ंको सलाह दी जाती है की चना एवं मसूर म द... 21 CHICK PEA िनयं ण के िलए N.P.V @ 250 L.E ित हेेयर दर से ... 22 NaN कटुआ कीड़ा का कोप अिधक हो तो ोरपायरीफॉस 20 ईसी... 23 NaN घोल बनाकर जड़ के पास िछड़काव कर। 24 NaN Keeping in view of relative humidity farmers a... 25 NaN crop against attack of white rust. If infectio... 26 NaN 2 gram/ litre of water is advised. Monitoring ... 27 NaN bug and aphid is advised. Rogor 30 EC at the r... 28 MUSTARD of water are quite effective in controlling th... 29 NaN सापेि क आ ता को ान म रखते ए िकसानो ंको सलाह दी... 30 NaN िनगरानी करते रह। यिद सं मण अिधक है तो Dithane-... 31 NaN बनाकर िछड़काव करे। मा या एिफड को िनयंि त करने... 32 NaN लीटर पानी म घोल बनाकर िछड़काव करे 它为crop Specific Advisory中的每个新行制作了不同的行如何合并这些行,我可以说新条目到来时会有英文的意思

python pandas dataframe datatable
1个回答
0
投票

您可以先使用fillna并将其与分组依据结合使用。

df = df.fillna(method='ffill')
df.groupby('Crop(Varieties)')['Crop Specific Advisory'].apply(lambda x: "{%s}" % ', '.join(x))

[fillnaffill用上面的单词替换NaN(“前填充”),groupby只是将每种作物的所有行合并为一个字符串。

© www.soinside.com 2019 - 2024. All rights reserved.