iterate over pandas dataframe and update the value – AttributeError: can’t set attribute

First iterating in pandas is possible, but very slow, so another vectorized solution are used. I think you can use iterrows if you need iterating: for idx, row in df.iterrows(): if df.loc[idx,’Qty’] == 1 and df.loc[idx,’Price’] == 10: df.loc[idx,’Buy’] = 1 But better is to use vectorized solutions – set value by boolean mask with … Read more

Python Pandas – Concat dataframes with different columns ignoring column names

If the columns are always in the same order, you can mechanically rename the columns and the do an append like: Code: new_cols = {x: y for x, y in zip(df_uk.columns, df_ger.columns)} df_out = df_ger.append(df_uk.rename(columns=new_cols)) Test Code: df_ger = pd.read_fwf(StringIO( u””” index Datum Zahl1 Zahl2 0 1-1-17 1 2 1 2-1-17 3 4″””), header=1).set_index(‘index’) df_uk … Read more

Plot Pandas DataFrame as Bar and Line on the same one chart

The DataFrame plotting methods return a matplotlib AxesSubplot or list of AxesSubplots. (See the docs for plot, or boxplot, for instance.) You can then pass that same Axes to the next plotting method (using ax=ax) to draw on the same axes: ax = df_13_14_target[[‘month’,’2014_target_val’]].plot(x=’month’,linestyle=”-“, marker=”o”) df_13_14_target[[‘month’,’2013_val’,’2014_val’]].plot(x=’month’, kind=’bar’, ax=ax) import pandas as pd import matplotlib.pyplot as … Read more

How to print DataFrame on single line

You need set: pd.set_option(‘expand_frame_repr’, False) option_context context manager has been exposed through the top-level API, allowing you to execute code with given option values. Option values are restored automatically when you exit the with block: #temporaly set expand_frame_repr with pd.option_context(‘expand_frame_repr’, False): print (df) Pandas documentation.

Removing duplicates from Pandas rows, replace them with NaNs, shift NaNs to end of rows

You can stack and then drop_duplicates that way. Then we need to pivot with the help of a cumcount level. The stack preserves the order the values appear in along the rows and the cumcount ensures that the NaN will appear in the end. df1 = df.stack().reset_index().drop(columns=”level_1″).drop_duplicates() df1[‘col’] = df1.groupby(‘level_0′).cumcount() df1 = (df1.pivot(index=’level_0’, columns=”col”, values=0) … Read more

Removing the timestamp from a datetime in pandas dataframe

You can do the following: dfST[‘timestamp’] = pd.to_datetime(dfST[‘timestamp’]) to_datetime() will infer the formatting of the date column. You can also pass errors=”coerce” if the column contains non-date values. After completing the above, you’ll be able to create a new column containing only date values: dfST[‘new_date_column’] = dfST[‘timestamp’].dt.date

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)