extract month from date in python
import datetime a=”2010-01-31″ datee = datetime.datetime.strptime(a, “%Y-%m-%d”) datee.month Out[9]: 1 datee.year Out[10]: 2010 datee.day Out[11]: 31
import datetime a=”2010-01-31″ datee = datetime.datetime.strptime(a, “%Y-%m-%d”) datee.month Out[9]: 1 datee.year Out[10]: 2010 datee.day Out[11]: 31
You can use clip. Apply to all columns of the data frame: df.clip(upper=15) Otherwise apply to selected columns as seen here: df.clip(upper=pd.Series({‘a’: 15}), axis=1)
there is even a shorter one 🙂 print df.groupby(‘name’).describe().unstack(1) Nothing beats one-liner: In [145]: print df.groupby(‘name’).describe().reset_index().pivot(index=’name’, values=”score”, columns=”level_1″)
Creating an empty dataframe with the same index and columns as another dataframe: import pandas as pd df_copy = pd.DataFrame().reindex_like(df_original)
Another alternative: df[‘week_start’] = df[‘myday’].dt.to_period(‘W’).apply(lambda r: r.start_time) This will set ‘week_start’ to be the first Monday before the time in ‘myday’. You can choose different week starts via anchored offsets e.g. ’W-THU’ to start the week on Thursday instead. (Thanks @Henry Ecker for that suggestion)
import pandas as pd pd.read_csv(“your_file.txt”, engine=”python”) Try this. It totally worked for me. source : http://kkckc.tistory.com/187
To calculate all the p-values at once, you can use calculate_pvalues function (code below): df = pd.DataFrame({‘A’:[1,2,3], ‘B’:[2,5,3], ‘C’:[5,2,1], ‘D’:[‘text’,2,3] }) calculate_pvalues(df) The output is similar to the corr() (but with p-values): A B C A 0 0.7877 0.1789 B 0.7877 0 0.6088 C 0.1789 0.6088 0 Details: Column D is automatically ignored as it … Read more
First: Do not post images of data, text only please Second: Do not paste data in the comments section or as an answer, edit your question instead How to quickly provide sample data from a pandas DataFrame There is more than one way to answer this question. However, this answer isn’t meant as an exhaustive … Read more
This behavior is intended, as an optimization. See the docs: In the current implementation apply calls func twice on the first column/row to decide whether it can take a fast or slow code path. This can lead to unexpected behavior if func has side-effects, as they will take effect twice for the first column/row.