unable to find column name after transpose

  • Last Update :
  • Techknowledgy :

EDIT So the code, as it works for me is as follows

df = pd.read_csv('StackoverflowGap.csv', na_values = missing_values, header = None)
df = df.T
df.columns = df.iloc[0]
df = df.reindex(df.index.drop('country'))
df.index.name = 'Year'
plt.figure(figsize = (12, 8))
plt.plot(df[['Canada', 'Cameroon']], linewidth = 0.5)
plt.title("Time Series for Canada")
plt.show()

Suggestion : 2

After transposing my Python Dataframe, I anycodings_dataframe could not access my column name to plot a anycodings_dataframe graph. I want to choose two columns but anycodings_dataframe failed. It keeps saying no such column anycodings_dataframe names. I am pretty new to Python, dataframe anycodings_dataframe and transpose. Could someone help please?,Below is my input file and I want to anycodings_dataframe transpose row to Column. It was successful anycodings_dataframe when I transposed but I could not select anycodings_dataframe "Canada" and "Cameroon" to plot a graph.,There a few things you might need to do anycodings_transpose when working with the data.,When you transpose, you need to name the columns df.columns= df.iloc[0].

Below is my input file and I want to anycodings_dataframe transpose row to Column. It was successful anycodings_dataframe when I transposed but I could not select anycodings_dataframe "Canada" and "Cameroon" to plot a graph.

    country 1990 1991 1992 1993 1994 1995
    0 Cambodia 65.4 65.7 66.2 66.7 67.1 68.4
    1 Cameroon 63.9 63.7 64.7 65.6 66.6 67.6
    2 Canada 98.6 99.6 99.6 99.8 99.9 99.9
    3 Cape Verde 77.7 77.0 76.6 89.0 79.0 78.0
    import pandas as pd
    import numpy as np
    import re
    import math
    import matplotlib.pyplot as plt

    missing_values = ["n/a", "na", "-", "-", "N/A"]
    df = pd.read_csv('StackoverflowGap.csv', na_values = missing_values)
    # Transpose
    df = df.transpose()
    plt.figure(figsize = (12, 8))
    plt.plot(df['Canada', 'Cameroon'], linewidth = 0.5)
    plt.title("Time Series for Canada")
    plt.show()

EDIT So the code, as it works for me is anycodings_transpose as follows

df = pd.read_csv('StackoverflowGap.csv', na_values = missing_values, header = None)
df = df.T
df.columns = df.iloc[0]
df = df.reindex(df.index.drop('country'))
df.index.name = 'Year'
plt.figure(figsize = (12, 8))
plt.plot(df[['Canada', 'Cameroon']], linewidth = 0.5)
plt.title("Time Series for Canada")
plt.show()

Suggestion : 3

‎08-21-2019 02:25 PM

 

proc contents data = sashelp.class;
run;

 

proc contents data = sashelp.class;
run;

Suggestion : 4

may not work unless x already has dimnames, since this will create a length-3 value from the NULL value of rownames(x). ,a valid value for that component of dimnames(x). For a matrix or array this is either NULL or a character vector of non-zero length equal to the appropriate dimension.,If the replacement versions are called on a matrix without any existing dimnames, they will add suitable dimnames. But constructions such as ,For a data frame, value for rownames should be a character vector of non-duplicated and non-missing names (this is enforced), and for colnames a character vector of (preferably) unique syntactically-valid names. In both cases, value will be coerced by as.character, and setting colnames will convert the row names to character.

Usage

rownames(x, do.NULL = TRUE, prefix = "row")
rownames(x) < -value

colnames(x, do.NULL = TRUE, prefix = "col")
colnames(x) < -value

If the replacement versions are called on a matrix without any existing dimnames, they will add suitable dimnames. But constructions such as

    rownames(x)[3] < -"c"

Examples

m0 < -matrix(NA, 4, 0)
rownames(m0)

m2 < -cbind(1, 1: 4)
colnames(m2, do.NULL = FALSE)
colnames(m2) < -c("x", "Y")
rownames(m2) < -rownames(m2, do.NULL = FALSE, prefix = "Obs.")
m2