Python 如何合并dataframe的行
我尝试使用tabla从pdf中获取表格,得到了如下数据帧Python 如何合并dataframe的行,python,pandas,dataframe,Python,Pandas,Dataframe,我尝试使用tabla从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
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 लीटर पानी म घोल बनाकर िछड़काव करे
它正在为作物特定咨询中的每一新行生成不同的行
如何合并这些行,
我可以说,当一个新条目出现时,英语中有一些东西您可以首先使用
fillna
并将其与groupby组合
df = df.fillna(method='ffill')
df.groupby('Crop(Varieties)')['Crop Specific Advisory'].apply(lambda x: "%s" % ''.join(x))
fillna
和ffill
将NaN替换为上面的单词(“正向填充”),groupby将每个裁剪的所有行简单地组合成一个字符串
输入:
Crop(Varieties) Crop Specific Advisory
0 MUSTARD a
1 NaN b
2 NaN c
3 NaN d
4 MAIZE e
5 NaN f
6 NaN g
7 WHEAT h
8 NaN i
9 NaN j
10 NaN k
11 NaN l
12 BENGAL m
13 NaN n
14 NaN o
15 NaN p
输出:
Crop Specific Advisory
Crop(Varieties)
BENGAL mnop
MAIZE efg
MUSTARD abcd
WHEAT hijkl