![]() ![]() Max_index = datetime(2050, 5, 3, 23, 59, 0)ĭf = pd.DataFrame(data=pd.date_range(start=min_index, end=max_index, freq = "H"), columns=)ĭf = df.dt.strftime("%A")ĭf = ) for a in range(df.shape)]ĭf = df.mask(np.random.random(df.shape) < 0.1)ĭf1 = df.astype(str) #same pb with apply(str)ĭf1.isnull().sum().sum() # return 0 which is wrongĭf2.isnull().sum(). You can compare results on this df: import pandas as pd If you want the actual dtype to be string (rather than object) and/or if you need to handle datetime conversion in your df and/or you have NaN/None in you df. I realise this is an old question, but since that's the first things that comes up for df string conversion so IMHO it shall be up to date. The most modern would be using subprocess.checkoutput and passing textTrue (Python 3. On average map(str) and apply(str) are takes less time compare with remaining two techniques Since this question is actually asking about subprocess output, you have more direct approaches available. If you run multiple times, time for each technique might vary. Print('time taken for apply(str) : ' + str(time.time()-time4) + ' seconds') Print('time taken for map(str) : ' + str(time.time()-time3) + ' seconds') Print('time taken for values.astype(str) : ' + str(time.time()-time2) + ' seconds') Print('time taken for astype(str) : ' + str(time.time()-time1) + ' seconds') Lets see the performance of each type #importing libraries astype(str)ĭf = df.astype(str)ĭf = df.values.astype(str)ĭf = df.map(str)ĭf = df.apply(str) ![]() ![]() There are four ways to convert columns to string 1. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |