« first day (40 days earlier)      last day (60 days later) » 

6:45 AM
Hi @Dandal :)
 
hello Shubham :D
 
Seen your comment, exactly what problem/error are you facing?
Can you please elaborate?
Here's our code:
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)
 
when defining the data and running the script, it tells me that df depends on g, and g depends on df
 
Can you share the complete error message?
 
raceback (most recent call last):
File "D:/Selenium/Face python 3.8/PJUDFinal/PJUDFinal/spiders/Otros/4 rol tribunal faltantes.py", line 17, in <module>
g = df['col1'].lt(df['col1'].shift()).cumsum()
NameError: name 'df' is not defined
 
6:50 AM
df is the name of your dataframe..i guess you are using f as the name so either replace f with df or df with f..
rawtext = parser.from_file('D:\Selenium\Texto.txt')
text = rawtext['content']
f = io.StringIO(text)
f.readline()
data = f.read()
f.readline()
This code seems problematic...
You have not initialized any dataframe..First you need to create the dataframe..
 
rawtext = parser.from_file(r"D:\Selenium\ faltantes.txt")
text = rawtext['content']
f = io.StringIO(text)
f.readline()
df = f.read()

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)
So?
 
While pasting code here select the code and press CTRL + K to autoformat it nicely..
That's not how you create a dataframe :)...Can you share the contents of the text first few lines..
df = f.read() is wrong..
 
rawtext = parser.from_file(r"D:\Selenium\ faltantes.txt")
text = rawtext['content']
f = io.StringIO(text)
f.readline()
df = f.read()

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)
why?
 
So that i could be able to help you create a dataframe..
 
df = f.read() is wrong.. why is wrong?
 
7:00 AM
@Dandal f.read() returns string not the dataframe...
Some thing like this should work:
f = io.StringIO(text)
df = pd.read_csv(f, sep='\s+', header=None, names=['col1', 'col2'])


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 _, g in df.groupby(g)], ignore_index=True)
If you text is in the format:
1029 400
1035 400
1031 340
1039 340
1020 503
1025 503
 
:O thx u bro
It is possible to remove the series that I submit from the list?
 
Can you elaborate?
 
the truth is that you did everything. I was missing this line pd.read_csv (f, sep = '\ s +', header = None, names = ['col1', 'col2'])
 
yes :)
 
7:23 AM
your answers are quite useful, and you answer a lot, you should add a Patreon link to your profile.
Thank you very much for the help Shubhamshu
 
@Dandal Thanks for the suggestion...really appreciate it :)
@Dandal happy to help :-)
 
 
3 hours later…
10:47 AM
room topic changed to DS5: [dataframe] [pandas] [python]
 

« first day (40 days earlier)      last day (60 days later) »