I'm trying to create a function that fills in missing numbers in multiple series, with different numerical scales, and at the same time generates a constant column for each of the series.
from tika import parser
import pandas as pd
import numpy as np
import io
rawtext = parser.from_file('D:\Selenium\Texto.txt')
text = rawtext['content']
f = io.StringIO(text)
f.readline()
data = f.read()
f.readline()
def fill(d):
idx = range(d['col1'].min(), d['col1'].max() + 1)
return d.set_index('col1').reindex(idx, method='ffill').reset_index()
g = df['col1'].lt(df['col1'].shift()).cumsum()
df = pd.concat([fill(g) for k, g in df.groupby(g)], ignore_index=True)
print(df)
Is it possible to create the following function with Pandas?
Sample dataframe:
1029 400
1035 400
1031 340
1039 340
1020 503
1025 503
Expected output:
1029 400
1030 400
1031 400
1032 400
1033 400
1034 400
1035 400
1031 340
1032 340
1033 340
1034 340
1035 340
1036 340
1037 340
1038 340
1039 340
1020 503
1021 503
1022 503
1023 503
1024 503
1025 503