pandas add dataframe to the bottom of another code example
Example 1: pandas add dataframe to the bottom of another
new_dataframe = old_dataframe.filter(['Columns','you','want'], axis=1)
Example 2: python count the number of zeros in each row of a pandas dataframe
(pandas_dataframe == 0).sum(axis=1)
import pandas as pd
pandas_dataframe = pd.DataFrame({'a':[1,0,0,1,3],
'b':[0,0,1,0,1],
'c':[0,0,0,0,0]})
a b c
0 1 0 0
1 0 0 0
2 0 1 0
3 1 0 0
4 3 1 0
(pandas_dataframe == 0).sum(axis=1)
0 2
1 3
2 2
3 2
4 1
Example 3: python seaborn violin plot fit data better
import numpy as np
import seaborn as sns
import matplotlib.pyplot as plt
data = np.random.rand(100)
sns.violinplot(y=data, bw=0.1)
Example 4: r return index of rows that have NA in dataframe
which(is.na(your_dataframe), arr.ind=TRUE)
Example 5: python obtain data from pandas dataframe without index name
df.to_string(index = False)
Example 6: pandas add dataframe to the bottom of another
import pandas as pd
appended_dataframe = dataframe_1.append(dataframe_2)
appended_dataframe = pd.concat([dataframe_1, dataframe_2])
dataframe_1 = pd.DataFrame([[1, 2], [3, 4]], columns=list('AB'))
dataframe_2 = pd.DataFrame([[5, 6], [7, 8]], columns=list('AB'))
appended_dataframe = dataframe_1.append(dataframe_2)
print(appended_dataframe)
A B
0 1 2
1 3 4
0 5 6
1 7 8
A B C D
0 1.0 2.0 NaN NaN
1 3.0 4.0 NaN NaN
0 NaN NaN 5.0 6.0
1 NaN NaN 7.0 8.0